Skip to content

fix(io): attempt to optimize loading/storing i/o#33

Merged
chrisdickinson merged 1 commit intomainfrom
chris/20230927-silly-optimization
Nov 17, 2023
Merged

fix(io): attempt to optimize loading/storing i/o#33
chrisdickinson merged 1 commit intomainfrom
chris/20230927-silly-optimization

Conversation

@chrisdickinson
Copy link

Move the if check out of the main loop so we don't branch on each pass and use bitwise operations to get the 8-byte chunk count & remainder. The resulting generated code is a little bit smaller (by 2k bytes or so) but runs about the same speed. (This is unsurprising in retrospect: these are the sorts of changes an optimizing compiler might perform!) I used hyperfine 1 and the extism CLI to test count_vowels 100 times against /usr/share/dict/words.

This was useful primarily from a "getting my fingerprints on the problem space" perspective, so we might not end up using these changes. I present them here because, well, they were fun to write 😄

Additionally, fix clippy lints.

@chrisdickinson chrisdickinson changed the title fix(io): slightly optimize loading/storing i/o fix(io): attempt to optimize loading/storing i/o Sep 29, 2023
Move the `if` check out of the main loop so we don't branch on each pass and
use bitwise operations to get the 8-byte chunk count & remainder. The resulting
generated code is a little bit smaller (by 2k bytes or so) but runs about the
same speed. (This is unsurprising in retrospect: these are the sorts of changes
an optimizing compiler might perform!) I used hyperfine [1] and the extism CLI
to test `count_vowels` 100 times against `/usr/share/dict/words`.

This was useful primarily from a "getting my fingerprints on the problem space"
perspective.

Additionally, fix clippy lints.

[1]: https://github.com/sharkdp/hyperfine
@chrisdickinson chrisdickinson force-pushed the chris/20230927-silly-optimization branch from 2b594a0 to 81582a9 Compare November 17, 2023 18:41
@chrisdickinson chrisdickinson marked this pull request as ready for review November 17, 2023 18:44
Copy link
Contributor

@zshipko zshipko left a comment

Choose a reason for hiding this comment

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

Thanks! I think regardless of the performance this is much nicer. I just started porting this over to the c-pdk and will probably do go too.

@chrisdickinson
Copy link
Author

Thanks! mtb0x1 also brought up a good point in Discord – we might consider adding {load,store}_v128 values as well to speed things up!

@chrisdickinson chrisdickinson merged commit 59c5ae1 into main Nov 17, 2023
@zshipko zshipko deleted the chris/20230927-silly-optimization branch November 17, 2023 19:13
@zshipko
Copy link
Contributor

zshipko commented Nov 17, 2023

Good point - I will make an issue on extism/extism for that!

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