Use arity hashCode instead of proc#hash in CallableSelector#4494
Use arity hashCode instead of proc#hash in CallableSelector#4494kares merged 1 commit intojruby:masterfrom
Conversation
Using proc#hash as the cache key means that you're only guaranteed to get a cache hit if exactly the same proc is being passed. Using arity.hashCode instead should satisfy the original reason for hashing the proc (disambiguate signatures based on the arity of the proc) while preventing cache misses. Also note that this was causing a memory leak: executing the code that relies on this caching would create a new cache entry on every invocation, slowly growing the size of the cache.
|
thanks @snowp ... vaguely recall this logic. |
|
I can look into adding a test to verify that the correct Java method gets called, but not sure how to test the cache growth? Here's some code I used to demonstrate the leak: causes: |
|
actually, looks like the method resolution is already tested in integration_spec.rb:213. i don't expect my change to cause any functional change, so not sure if adding more functional tests would be helpful? |
|
you're right - looked closer and only the arity matters at that ( |
Using proc#hash as the cache key means that you're only
guaranteed to get a cache hit if exactly the same proc is
being passed. Using arity.hashCode instead should satisfy the
original reason for hashing the proc (disambiguate signatures
based on the arity of the proc) while preventing cache misses.
Also note that this was causing a memory leak: each time we get a cache miss it creates a new cache entry, and the cache is unbounded.
Tried to add a test for this, but it doesn't seem like CallableSelectorTest runs / works.