[JAVA-4751] Simplify CodecCache Created: 06/Oct/22  Updated: 18/Oct/22  Resolved: 18/Oct/22

Status: Closed
Project: Java Driver
Component/s: Internal
Affects Version/s: None
Fix Version/s: 4.8.0

Type: Improvement Priority: Minor - P4
Reporter: Valentin Kavalenka Assignee: Valentin Kavalenka
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Gantt Dependency
has to be done after JAVA-4745 Handle recursive types in parameteriz... Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed

 Description   

Working on this ticket requires resolving JAVA-4745 / merging https://github.com/mongodb/mongo-java-driver/pull/1007 to avoid conflicts. The ticket is spawned as a result of this discussion.

Currently CodecCache.putIfMissing puts in a ConcurrentMap, but nevertheless is guarded with synchronized and does two put}}s for the same key. If we use {{ConcurrentMap.compute to reimplement the method, we can not only get rid of these oddities, but also improve its performance and, also importantly, readability.

Tangentially related to the above improvement, methods OverridableUuidRepresentationCodecRegistry.get, ProvidersCodecRegistry.get do two map lookups instead of one on the happy path, because they both use the anti-pattern "check if a binding is there and then find the binding again, this time return the value". This is also worth changing.



 Comments   
Comment by Githook User [ 18/Oct/22 ]

Author:

{'name': 'Valentin Kovalenko', 'email': 'valentin.kovalenko@mongodb.com', 'username': 'stIncMale'}

Message: Simplify `CodecCache` (#1018)

JAVA-4751
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b1f4e3cc0acc92ab55ea8fb8044dccd41967a742

Generated at Thu Feb 08 09:02:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.