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

Add DynamicProxyObject to fix time-consuming "getter"-methods #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

wuarmin
Copy link

@wuarmin wuarmin commented Oct 7, 2017

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.

@wuarmin wuarmin changed the title Add DynamicProxyObject to fix time-consuming "getter"-methods #99 Add DynamicProxyObject to fix time-consuming "getter"-methods Oct 7, 2017

def method_missing(name, *args, &block)
key = cache_key(name, args)
@cache[key] ||= @target.send(name, *args, &block)

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.

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]

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

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.

@wuarmin
Copy link
Author

wuarmin commented Jul 29, 2018

@krainboltgreene thank you for your review. I'll address your proposals.

@krainboltgreene
Copy link

@wuarmin FWIW I don't envy your task! Cache-level optimizations are hard and can be unpredictable at the library level.

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.

2 participants