Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4751

Simplify CodecCache

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.8.0
    • Affects Version/s: None
    • Component/s: Internal
    • None
    • Fully Compatible
    • Not Needed

      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.

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: