-
Notifications
You must be signed in to change notification settings - Fork 91
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
Add DynamicProxyObject to fix time-consuming "getter"-methods #112
base: master
Are you sure you want to change the base?
Conversation
|
||
def method_missing(name, *args, &block) | ||
key = cache_key(name, args) | ||
@cache[key] ||= @target.send(name, *args, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be public_send
, for maximum clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ||=
will be a good enough check. Different args or a block should produce different results.
def method_missing(name, *args, &block) | ||
key = cache_key(name, args) | ||
@cache[key] ||= @target.send(name, *args, &block) | ||
@cache[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be deleted. All ruby ...=...
syntax always returns the right most expression.
return nil unless objects | ||
if objects.respond_to?(:map) | ||
objects.map { |obj| DynamicProxyObject.new(obj) } | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO respond_to?(:map)
is too weak of a trait check. Any object could have the method map
and not be a collection.
@krainboltgreene thank you for your review. I'll address your proposals. |
@wuarmin FWIW I don't envy your task! Cache-level optimizations are hard and can be unpredictable at the library level. |
Hello ;)
What is your opinion on my proposal?
It solves huge performance issues for us, because we are dealing with objects with slow and unchangeable getter-methods.
We had a conversation at #99.
Thank you for your feedback.