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

Simplify CodecCache

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Done
    • None
    • 4.8.0
    • Internal
    • None
    • Fully Compatible
    • 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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: