Skip to content
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

Use multiple locks in ByteBuddyMockFactory to reduce lock contention #1778

Merged
merged 1 commit into from Sep 10, 2023

Conversation

AndreasTu
Copy link
Member

@AndreasTu AndreasTu commented Sep 3, 2023

Changed locking scheme in ByteBuddyMockFactory from a single global lock CACHE to cacheLocks with size 16.
The used TypeCachingLock from cacheLocks depends on the hashcode of TypeCache.SimpleKey,
which aggregates the types to mock.

The old global CACHE lock did block Threads regardless, if they try to mock the same type or not.

This is a similar fix as in Mockito:
Mockito 3095

@codecov
Copy link

codecov bot commented Sep 3, 2023

Codecov Report

Patch coverage: 95.23% and project coverage change: +79.83% 🎉

Comparison is base (31985e3) 0.00% compared to head (c84f558) 79.83%.

❗ Current head c84f558 differs from pull request most recent head 171cee9. Consider uploading reports for the commit 171cee9 to get more accurate results

Additional details and impacted files
@@              Coverage Diff              @@
##             master    #1778       +/-   ##
=============================================
+ Coverage          0   79.83%   +79.83%     
- Complexity        0     4077     +4077     
=============================================
  Files             0      425      +425     
  Lines             0    12916    +12916     
  Branches          0     1630     +1630     
=============================================
+ Hits              0    10311    +10311     
- Misses            0     1998     +1998     
- Partials          0      607      +607     
Files Changed Coverage Δ
...kframework/mock/runtime/ProxyBasedMockFactory.java 81.25% <85.71%> (ø)
...ckframework/mock/runtime/ByteBuddyMockFactory.java 90.47% <100.00%> (ø)

... and 423 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Changed locking scheme in ByteBuddyMockFactory from a
single global lock CACHE to cacheLocks with size 16.
The used TypeCachingLock from cacheLocks depends on
the hashcode of TypeCache.SimpleKey, which aggregates the types to mock.

The old global CACHE lock did block Threads regardless,
if they try to mock the same type or not.

This is a similar fix as in Mockito:
mockito/mockito#3095

Co-authored-by: Björn Kautler <Bjoern@Kautler.net>
Copy link
Member

@Vampire Vampire left a comment

Choose a reason for hiding this comment

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

LGTM, thx

@Vampire Vampire merged commit d660020 into spockframework:master Sep 10, 2023
21 checks passed
@AndreasTu AndreasTu deleted the MockLock branch September 11, 2023 13:39
leonard84 added a commit to AndreasTu/spock that referenced this pull request Sep 15, 2023
…ctedConst

* spockframework/master:
  Use multiple locks in ByteBuddyMockFactory to reduce lock contention (spockframework#1778)
  Fixup LICENSE file after change to geantyref (spockframework#1773)

# Conflicts:
#	spock-core/src/main/java/org/spockframework/mock/runtime/ByteBuddyMockFactory.java
@AndreasTu AndreasTu added this to the 2.4 milestone Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants