[GODRIVER-2990] Use type switch for BSON default registry Created: 18/Sep/23  Updated: 18/Sep/23

Status: Backlog
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on GODRIVER-2973 Implement Go Driver 2.0: BSON Library Scheduled
Related

 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.

Generated at Thu Feb 08 08:39:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.