Skip to content

Optimize shadow stack pass #1667

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

Merged
merged 4 commits into from
Feb 22, 2021
Merged

Optimize shadow stack pass #1667

merged 4 commits into from
Feb 22, 2021

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Feb 4, 2021

This is an experiment to reduce overhead of the shadow stack pass. The pass is currently maintaining more stack slots than necessary (anywhere something managed naively goes to the stack) to be sure, but there is room for improvement.

The relatively simple changes in this PR reduce optimized binary size by about 10% and increase throughput by a little less than 10% (testing with the compiler). Optimizations here are risky, though, because any mistake, not only in the shadow stack pass itself but also in compiler code, for instance where an actually necessary (pre-)instrumentation is missing, can lead to unforeseen consequences that only show themselves randomly.

As such it may make sense to test with various programs and various GC configurations first to minimize the risk.

  • I've read the contributing guidelines

@MaxGraey
Copy link
Member

any updates? I know this is not huge improvement but still improvement =)

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 20, 2021

I guess we could just give it a try, but there is a potential for unexpected breakage there. On the other hand, without actually using it in the wild, it may be hard to find problems as these can be quite random.

@MaxGraey
Copy link
Member

How about hide this changes under some experimental flag? And ask people turn it on for testing on real projects? But by default turn it off

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 20, 2021

Hmm, in this case this may actually work. Going to check :)

@MaxGraey
Copy link
Member

Or just add extra "incremental-experimental" mode for runtime

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 21, 2021

Together with #1692:

// JS
I/O Read   :    25.798 ms  n=106
I/O Write  :    71.081 ms  n=3
Parse      :   423.531 ms  n=164
Initialize :    36.616 ms  n=1
Compile    :  1858.461 ms  n=1
Emit       :  2184.024 ms  n=3
Validate   :   246.967 ms  n=1
Optimize   : 65314.422 ms  n=1
Transform  :          n/a  n=0

// Wasm
I/O Read   :    20.495 ms  n=106
I/O Write  :    94.715 ms  n=3
Parse      :   284.738 ms  n=164  <
Initialize :    10.400 ms  n=1    <
Compile    :  1339.539 ms  n=1    <
Emit       :  2369.944 ms  n=3
Validate   :   267.235 ms  n=1
Optimize   : 72261.810 ms  n=1
Transform  :          n/a  n=0

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 21, 2021

Currently running this branch against Rtrace and worst-case config options, similar to what has been done in initial bootstrapping, and so far is looking good.

@MaxGraey
Copy link
Member

Could you also test with assemblyscript-regexp? I guess it pretty great battletest example

@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 21, 2021

Did that now (after figuring out how), and it passes the tests.

For everyone curious, this is how one can do it without hitting any of the errors (missing dist files, missing transforms, ...) I've encountered while trying more convenient things. In your local AS fork:

npm run build
node scripts/prepublish
npm pack
node scripts/postpublish

then replace node_modules/assemblyscript with the contents of assemblyscript.tar.gz in the dependency graph of your module.

@dcodeIO dcodeIO marked this pull request as ready for review February 22, 2021 12:35
@dcodeIO
Copy link
Member Author

dcodeIO commented Feb 22, 2021

Unable to provoke problems here, so probably not worth the trouble to introduce a flag. Suggesting to release it into the wild.

@dcodeIO dcodeIO requested a review from MaxGraey February 22, 2021 12:37
Copy link
Member

@MaxGraey MaxGraey left a comment

Choose a reason for hiding this comment

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

Overall LGTM

@dcodeIO dcodeIO merged commit d4e7b9d into master Feb 22, 2021
@dcodeIO dcodeIO deleted the optimize-shadowstack branch June 1, 2021 15:20
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