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

refactor(swingset-liveslots): stateShape causes accessor sharing #7286

Closed
wants to merge 1 commit into from

Conversation

erights
Copy link
Member

@erights erights commented Mar 30, 2023

When a kind is provided with a stateShape, we know exactly what the names are for all of the state fields across all instances. For that case, it is wasteful to create accessor properties per instance. So instead, when there is a stateShape, this PR will instead install similar accessors on a shared statePrototype object. Each state object is them a frozen empty object that inherits from that statePrototype. As with a shared prototype for methods, to make this work, we also introduce a separate stateToInnerSelf weakmap, so the accessor can get the correct innerSelf from its this, which is the empty state instance itself.

See also
#7289
#6693
#7138

@erights erights self-assigned this Mar 30, 2023
@erights erights force-pushed the markm-state-proto branch from d7f9d82 to a504719 Compare March 31, 2023 01:20
@erights erights requested review from warner, gibson042 and FUDCo March 31, 2023 01:55
@erights erights changed the title WIP fix: stateShape causes accessor sharing refactor(swingset-liveslots): stateShape causes accessor sharing Mar 31, 2023
@erights erights marked this pull request as ready for review March 31, 2023 01:56
@erights erights requested a review from mhofman March 31, 2023 02:01
@warner
Copy link
Member

warner commented Mar 31, 2023

@erights That's really cool, and I look forward to using it. That file, however, is about to be changed drastically by #7138 , and I'm wondering if you could instead look at the target branch (6693-vo-lru-cache) and see if you can make the corresponding change to it instead? I replaced contextMap with a provideContext function, and innerSelf disappears entirely. I think the same approach can be made (and it should be a good bit simpler), but if we land it first, I'm going to spend days trying to understand how it works and changing my PR to match, whereas I bet you could make the same changes to my branch pretty quickly.

I'm going to be rebasing my branch heavily as I get it ready for review and landing (still fighting through some unit test changes now). If you make a branch based on the current 6693-vo-lru-cache, I'd be happy to manage any updates or rebasing that your branch needs as I make changes to my branch.

@erights erights marked this pull request as draft April 1, 2023 01:01
@erights
Copy link
Member Author

erights commented Apr 1, 2023

@warner understood. Good plan. I've converted this to draft at least until I rebase and reconcile with #7138

@warner
Copy link
Member

warner commented Apr 10, 2023

@erights 7338-store-state-shape is the branch to base your work on, it's still in review but barring changes it's what trunk should look like in a few days

Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thatsa very nice.

@erights
Copy link
Member Author

erights commented Apr 19, 2023

Closing in favor of #7444

@erights erights closed this Apr 19, 2023
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.

3 participants