Closed Seberius closed 9 years ago
This looks really good, its probably the closure that is adding all this cost.
Do you mind updating the benchmarks in the readme? We should try to stay in sync here. (though annoyingly you will have to rerun all of them)
I updated bench.rb to use .getset for lru_redux as it was about 1 second faster (I think its the extra lock with ||=). The docs for 'lru' specify to use ||=, so I believe this is fair. The readme has been updated with the new times.
Looks good to me!
Will leave it a few days before doing a new release, thanks heaps!
No problem, it was an interesting project.
Awesome, thanks heaps for all your help!
On Mon, Feb 16, 2015 at 4:37 PM, Seberius notifications@github.com wrote:
I updated bench.rb to use .getset for lru_redux as it was about 1 second faster (I think its the extra lock with ||=). The docs for 'lru' specify to use ||=, so I believe this is fair. The readme has been updated with the new times.
— Reply to this email directly or view it on GitHub https://github.com/SamSaffron/lru_redux/pull/5#issuecomment-74462056.
thanks again, got a new gem out!
On Mon, Feb 16, 2015 at 5:13 PM, Sam Saffron sam.saffron@gmail.com wrote:
Awesome, thanks heaps for all your help!
On Mon, Feb 16, 2015 at 4:37 PM, Seberius notifications@github.com wrote:
I updated bench.rb to use .getset for lru_redux as it was about 1 second faster (I think its the extra lock with ||=). The docs for 'lru' specify to use ||=, so I believe this is fair. The readme has been updated with the new times.
— Reply to this email directly or view it on GitHub https://github.com/SamSaffron/lru_redux/pull/5#issuecomment-74462056.
Hello, I experienced a significant performance drop running the included benchmark test when I switched it to
cache.getset(rand(2_000)) { :value }
fromcache[rand(2_000)] ||= :value
. I believe the culprit to be the coercion of yield blocks to Procs that occurs with the ThreadSafeCache synchronize class method. The new implementation is more verbose, but the performance gain is significant and it can easily be refactored as a mixin if needed (e.g. to support any new caches).Test:
New implementation was in its own class for testing.
Result:
The branch was passing all tests.