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

Use type switch for BSON default registry

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Unknown Unknown
    • None
    • None
    • BSON
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: