Skip to content

Introduce codec mapping caches (0.8.x branch) #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

frdeboffles
Copy link

Introduce codec mapping caches to improve encoding and decoding performances.

  • Refactored the codec registry to use a CodecFinder (default to SPI definition in the classpath)
  • Switched the codec list to a thread safe variant to avoid the synchronized blocks. Even though CopyOnWriteArrayList is not super performant it should work fine in this context where the list should not be frequently updated.
  • Provided 2 implementations of the codec finder, one without cache and another with cache
  • Added a build cache method that will attempt to fill the cache when the codecs are updated. This cannot covers all the cases like the nested arrays, therefore for those type the cache will be filled dynamically on per-request basis
  • Added microbenchmarks for codec encode and decode using the cache based implementation or not
  • Switched mockito-core to mockito-junit-jupiter for Junit 5 support
  • Disabled unixDomainSocketTest IT when running on Mac or Windows

JMH results:

Benchmark                                                (iterations)  (resultSize)   Mode  Cnt       Score      Error  Units
CodecRegistryBenchmarks.decodeWithCacheDisabledRegistry            10           N/A  thrpt    5   13456.082 ±  851.123  ops/s
CodecRegistryBenchmarks.decodeWithCacheDisabledRegistry           100           N/A  thrpt    5    1528.566 ±   35.987  ops/s
CodecRegistryBenchmarks.decodeWithCacheDisabledRegistry          1000           N/A  thrpt    5     152.652 ±    1.207  ops/s
CodecRegistryBenchmarks.decodeWithCacheEnabledRegistry             10           N/A  thrpt    5   27485.494 ±  302.008  ops/s
CodecRegistryBenchmarks.decodeWithCacheEnabledRegistry            100           N/A  thrpt    5    2821.798 ±    8.432  ops/s
CodecRegistryBenchmarks.decodeWithCacheEnabledRegistry           1000           N/A  thrpt    5     272.775 ±    0.643  ops/s
CodecRegistryBenchmarks.encodeWithCacheDisabledRegistry            10           N/A  thrpt    5   43370.774 ±  273.390  ops/s
CodecRegistryBenchmarks.encodeWithCacheDisabledRegistry           100           N/A  thrpt    5    4416.795 ±   72.559  ops/s
CodecRegistryBenchmarks.encodeWithCacheDisabledRegistry          1000           N/A  thrpt    5     430.082 ±    2.369  ops/s
CodecRegistryBenchmarks.encodeWithCacheEnabledRegistry             10           N/A  thrpt    5  193702.669 ± 2121.691  ops/s
CodecRegistryBenchmarks.encodeWithCacheEnabledRegistry            100           N/A  thrpt    5   19407.580 ±  179.642  ops/s
CodecRegistryBenchmarks.encodeWithCacheEnabledRegistry           1000           N/A  thrpt    5    1914.948 ±   12.990  ops/s

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Issue description

See gh-409

New Public APIs

Additional context

…decoding performances.

* Refactored the codec registry to use a CodecFinder (default to SPI definition in the classpath)
* Switched the codec list to a thread safe variant to avoid the synchronized blocks. Even though `CopyOnWriteArrayList` is not super performant it should work fine in this context where the list should not be frequently updated.
* Provided 2 implementations of the codec finder, one without cache and another with cache
* Added a build cache method that will attempt to fill the cache when the codecs are updated. This cannot covers all the cases like the nested arrays, therefore for those type the cache will be filled dynamically on per-request basis
* Added microbenchmarks for codec encode and decode using the cache based implementation or not
* Switched `mockito-core` to `mockito-junit-jupiter` for Junit 5 support
* Disabled unixDomainSocketTest IT when running on Mac or Windows
@mp911de mp911de changed the title gh-409: Introduce codec mapping caches (0.8.x branch) Introduce codec mapping caches (0.8.x branch) Sep 22, 2021
@mp911de mp911de added the type: enhancement A general enhancement label Sep 22, 2021
@mp911de mp911de added this to the 0.8.9.RELEASE milestone Sep 22, 2021
<postgresql.version>42.2.20</postgresql.version>
<logback.version>1.2.5</logback.version>
<mockito.version>3.12.4</mockito.version>
<netty.version>4.1.66.Final</netty.version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading dependencies isn't a concern that belongs into such a change.

@mp911de mp911de self-assigned this Sep 22, 2021
mp911de pushed a commit that referenced this pull request Sep 22, 2021
…rmances.

* Switched the codec list to a thread safe variant to avoid the synchronized blocks. Even though `CopyOnWriteArrayList` is not super performant it should work fine in this context where the list should not be frequently updated.

* Switched `mockito-core` to `mockito-junit-jupiter` for Junit 5 support
* Refactored the codec registry to use a CodecFinder (default to SPI definition in the classpath)
* Provided 2 implementations of the codec finder, one without cache and another with cache
* Added a build cache method that will attempt to fill the cache when the codecs are updated. This cannot covers all the cases like the nested arrays, therefore for those type the cache will be filled dynamically on per-request basis
* Added microbenchmarks for codec encode and decode using the cache based implementation or not
* Disabled unixDomainSocketTest IT when running on Windows

[#444][resolves #409]
mp911de added a commit that referenced this pull request Sep 22, 2021
Rename CodecFinder to CodecLookup. Rename default implementations to CachedCodecLookup and DefaultCodecLookup. Extract CodecMetadata interface and turn getFormats() into a default method.
Refactor how CodecLookup obtains its actual codecs to prevent methods allowing to alter the internal state of the cache component through updateCodecs(…). The delegate is typically a CodecRegistry for iteration over the actual codecs.

Reinstate socket tests on MacOS as sockets are supported on BSD via kqueue. Remove overly complex spy arrangements from tests.

Refine tests.

[resolves #444][#409]

Signed-off-by: Mark Paluch <[email protected]>
@mp911de
Copy link
Collaborator

mp911de commented Sep 22, 2021

Thank you for your contribution. That's merged and polished now.

@mp911de mp911de closed this Sep 22, 2021
@mp911de mp911de linked an issue Sep 22, 2021 that may be closed by this pull request
mp911de added a commit that referenced this pull request Sep 22, 2021
Fix benchmarks after polishing.

[#444][#409]

Signed-off-by: Mark Paluch <[email protected]>
@frdeboffles frdeboffles deleted the feature-gh-409-codec-mapping-cache-0.8.x branch September 22, 2021 15:58
mp911de added a commit that referenced this pull request Sep 23, 2021
Use constructor delegation in DefaultCodecs.

[#444][#409]

Signed-off-by: Mark Paluch <[email protected]>
mp911de added a commit that referenced this pull request Sep 23, 2021
Fix benchmarks after polishing.

[#444][#409]

Signed-off-by: Mark Paluch <[email protected]>
mp911de added a commit that referenced this pull request Sep 23, 2021
Use constructor delegation in DefaultCodecs.

[#444][#409]

Signed-off-by: Mark Paluch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance improvement on codec mapping
3 participants