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 some string/char related micro-optimizations #73

Merged
merged 7 commits into from
Jul 11, 2023

Conversation

tekknolagi
Copy link
Contributor

Together, these patches bring down wasm2c compile time of clang.wasm from 1.7s to 1.2s on my machine. Let me know if you would like these and if you would like me to squash.

@tekknolagi
Copy link
Contributor Author

stringBuilderAppendChar is now 12% of total instructions according to callgrind.

@tekknolagi
Copy link
Contributor Author

tekknolagi commented Jul 5, 2023

There's also probably some room to split out a version for C-string literals so that it can be inlined and the strlen can be folded away, which---if you want it---would also make writing characters faster on the current code without my patches.

EDIT: Nevermind, I think this already happens.

This takes clang.wasm compile time from 1.7s to 1.5s on my machine.
This takes clang.wasm compile time from 1.5s to 1.3s on my machine.
@tekknolagi
Copy link
Contributor Author

tekknolagi commented Jul 5, 2023

Rebased the strncpy->memcpy change out of existence since I am less sure about that one and it's not relevant in the PR, I think. I'll figure out how to run tests locally.

@tekknolagi
Copy link
Contributor Author

The tests look weirdly suspiciously broken, so I figured it was UB or something. Ran locally with -fsanitize=undefined and can't get them to fail :/

@tekknolagi
Copy link
Contributor Author

Also, further, I diffed clang.c before and after my changes and there is no difference...

w2c2/array.c Outdated Show resolved Hide resolved
@turbolent
Copy link
Owner

@tekknolagi Thank you for the optimizations, the numbers look great! I'll try to find time to investigate why the tests fail

Copy link
Owner

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Looks great!

There's a small issue with writing the minus sign, but after fixing it, all test pass (locally) 🎉

w2c2/c.c Outdated Show resolved Hide resolved
w2c2/c.c Outdated Show resolved Hide resolved
w2c2/c.c Outdated Show resolved Hide resolved
w2c2/c.c Outdated Show resolved Hide resolved
Co-authored-by: Bastian Müller <bastian@turbolent.com>
@turbolent turbolent merged commit 7e15999 into turbolent:main Jul 11, 2023
45 of 73 checks passed
@tekknolagi
Copy link
Contributor Author

🥳

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