Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2990

Use type switch for BSON default registry

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None

      Go BSON encoders/decoders currently use a "registry" to look up codecs for specific Go types, which uses a sync.Map to find the correct codec. However, that creates possible locking contention between goroutines, requires reflection calls, and uses a relatively slow map lookup compared to a simple type switch. The sync.Map lookup is only necessary when a customer overrides the default registry, which few customers do. Instead, it would be better to use a type switch for common Go types, only falling back to a sync.Map for custom registries or user-defined types.

      See ReflectionFreeDCodec type that was originally developed to significantly improve BSON encode/decode performance, specifically for the bson.D type.

      Definition of done:

      • Use a type switch to look up BSON codecs for common Go types when the user has not provided a custom registry.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: