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

More performance improvements. #2

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

Conversation

johncarney
Copy link
Owner

Builds on the previous performance-related pull request with a more radical variation on the class version of memoize. This time it defines a method that replaces itself with an attr_reader before setting the instance variable using the supplied block. This makes the first call to the memorised method very expensive, but subsequent calls become very cheap.

In testing, this yielded an impressive performance improvement when a memoized method was called a very large number of times in a given instance's lifetime. However, the break-even point was about 200 calls, so it's not really practical, but I thought I'd put it up for interest's sake.

@johncarney johncarney closed this Jul 16, 2015
@johncarney johncarney reopened this Jul 16, 2015
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.

1 participant