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

Faster cached views version 8: values on instance, notYetCached right on instance shape #95

Closed
wants to merge 1 commit into from

Conversation

airhorns
Copy link
Contributor

This implements a better performing getter function for readonly instances. Before this, we used the same definition of the getter function for all views, which ended up megamorphic, because it accessed a very wide variety of properties for every instance! Instead, this evals a monomorphic getter for each one. I also changed the object that stores the memos to have a fixed shape from birth by evaling it out as well.

I also changed us to use the object itself to store all the memoized values, instead of two other tracker objects. We were previously using the trackers in order to implement memoization of undefined and null correctly. Now, we set up symbol properties to store all the memos, but on the prototype of the class model. This means we don't spend any time setting them up during construction, but the JS VM knows the shape of the memos ahead of time! Less memory and same speed woop woop! Then, when memoizing, we can stash the value under that symbol key, which means fewer property accesses and lookups to fetch it.

…ched views

This implements a better performing getter function for readonly instances. Before this, we used the same definition of the getter function for all views, which ended up megamorphic, because it accessed a very wide variety of properties for every instance! Instead, this evals a monomorphic getter for each one. I also changed the object that stores the memos to have a fixed shape from birth by evaling it out as well.

I also changed us to use the object itself to store all the memoized values, instead of two other tracker objects. We were previously using the trackers in order to implement memoization of undefined and null correctly. Now, we set up symbol properties to store all the memos, but on the prototype of the class model. This means we don't spend any time setting them up during construction, but the JS VM knows the shape of the memos ahead of time! Less memory and same speed woop woop! Then, when memoizing, we can stash the value under that symbol key, which means fewer property accesses and lookups to fetch it.
@airhorns airhorns changed the title Eval a fast property memoizer to microoptimize property access for cached views Faster cached views version 8: values on instance, notYetCached right on instance shape May 31, 2024
Copy link

codspeed-hq bot commented May 31, 2024

CodSpeed Performance Report

Merging #95 will improve performances by 19.63%

Comparing faster-get-8 (070dc7b) with main (f183291)

Summary

⚡ 3 improvements
✅ 5 untouched benchmarks

Benchmarks breakdown

Benchmark main faster-get-8 Change
instantiating a large union 91.3 µs 83 µs +10.02%
accessing unmemoized getter properties of a class model 34.8 µs 31.4 µs +10.98%
accessing unmemoized null property of a class model 17.4 µs 14.6 µs +19.63%

@airhorns
Copy link
Contributor Author

I think this hurts instantiation performance too much, closing

@airhorns airhorns closed this May 31, 2024
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