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 a few optimizations to reduce the number of copies #194

Merged
merged 5 commits into from
Dec 3, 2020
Merged

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Dec 3, 2020

This adds infrastructure to delay the assembly of values so that they can if appropriate target the stack directly instead of always having to resort to copy the value from a position in the stack to the top of it.

This has several benefits:

  • This reduces peak memory use, since the stack will overall be smaller.
  • This reduces the number of ref count increase/decreases a value has to go through when operating over it. Like we do with the IndexGet operation (see use of Stack::address_ref which can even use a reference of the value).

My own benchmarks shows a 50% reduction in the number of copies in aoc_2020_1a and a ~10% performance gain.

Because this has to live side-by-side with the existing assembler, Asm has to support both modes:

  • Asm::apply will cause the assembly to generate the necessary instructions. No compiler state will be modified, since this is currently the norm.
  • Asm::apply_targeted will produce an InstTarget appropriate for the operation. If a value is copied onto the stack, it will be declared as anonymous. This should be used immediately in a scope so the scope can be cleaned up.

@udoprog udoprog force-pushed the opt-passes branch 3 times, most recently from f868857 to 46baf2e Compare December 3, 2020 20:14
@udoprog udoprog added the enhancement New feature or request label Dec 3, 2020
@udoprog udoprog force-pushed the opt-passes branch 3 times, most recently from ca1e8f5 to 8298edf Compare December 3, 2020 20:34
@udoprog udoprog merged commit c5d4f81 into main Dec 3, 2020
@udoprog udoprog deleted the opt-passes branch December 3, 2020 20:44
@udoprog udoprog added the changelog Issue has been added to the changelog label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant