Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: optimize string literal tostack behavior #2945

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
HerrCai0907 merged 2 commits into main from opt-static-string
Sep 6, 2025
Merged

Conversation

Copy link
Member

@HerrCai0907 HerrCai0907 commented Sep 5, 2025
edited
Loading

String literals are widely used static data, and our GC algorithm does not recycle them (see

if (changetype<usize>(obj) < __heap_base) {
). Recording the addresses of all string literals and preventing the emission of tostack code can effectively improve performance

String literals are widely used static data, and our GC algorithm does not recycle them (see https://github.com/AssemblyScript/assemblyscript/blob/7e2a62d9615d2ae02b593af87ee4920a3c57b0bd/std/assembly/rt/itcms.ts#L244). Recording the addresses of all string literals and preventing the emission of tostack code can effectively improve performance
Copy link
Member Author

In bootstrap parse, the execution time reduced from 210ms to 200ms.

Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

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

This optimization looks very promising (so cool that you found this!). I can definitely see the difficulty of making something equivalent to Set<i64> that works in the JS build.

My understanding of this PR is that you're trying to add the if (address < __heap_base) shortcut to the shadow stack generation code, and staticGcObjectOffsets is how you're trying to determine (for needToStack) whether some data is static data. Do you think it's possible to instead directly compare the address/offset to the value of __heap_base?

If this isn't easy or possible within the compiler, what would generating something like this (well, the isize equivalent) look like (assuming this idea is easy to do):

(if (i32.lt_u (local.get $address) (global.get $~lib/memory/__heap_base))
 (; insert tostack code here ;)
)

Would Binaryen optimize that out, even in debug builds? Just throwing some backup ideas out, because I'm not a huge fan of staticGcObjectOffsets (but if we can't do it any other way, I guess we have no choice).

Copy link
Member Author

HerrCai0907 commented Sep 5, 2025
edited
Loading

My understanding of this PR is that you're trying to add the if (address < __heap_base) shortcut to the shadow stack generation code, and staticGcObjectOffsets is how you're trying to determine (for needToStack) whether some data is static data. Do you think it's possible to instead directly compare the address/offset to the value of __heap_base?

That is wrong. e.g. StaticArray also in data segments but we should add it to stack otherwise all of the A in this array will be free.

The precise description should be the so-called pointee free type located in the static data area. But string literal is the most common used type. So I also add string to the map. But we can extend it later.

Copy link
Member

Ah, understood.

@HerrCai0907 HerrCai0907 merged commit 9664c5b into main Sep 6, 2025
14 checks passed
@HerrCai0907 HerrCai0907 deleted the opt-static-string branch September 6, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@CountBleck CountBleck CountBleck left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /