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

Avoid creating temporary vector copies when checking signature #2435

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

mjbshaw
Copy link
Contributor

@mjbshaw mjbshaw commented Jun 21, 2024

I was doing some local bench marking and found a significant amount of wasm-validate's time came from copying (and then destroying) temporary vectors here. Currently CheckSignature() is calling PrintStackIfFailed() and passing sig (which is already a `TypeVector), whic creates a copy. This change eliminates the unnecessary vector copy and adds a static assertion that should prevent this from happening again.

@sbc100
Copy link
Member

sbc100 commented Jun 21, 2024

Under what circumstances do these args end up being vectord? Multi-value?

@mjbshaw
Copy link
Contributor Author

mjbshaw commented Jun 22, 2024

I linked to where it happens in the comment. CheckSignature() is passing its sig vector to PrintStackIfFailed(). I don't see any other occurrances, though, so an easy alternative would be to change line 257 to use PrintStackIfFailedV() instead.

@sbc100
Copy link
Member

sbc100 commented Jun 22, 2024

I linked to where it happens in the comment. CheckSignature() is passing its sig vector to PrintStackIfFailed(). I don't see any other occurrances, though, so an easy alternative would be to change line 257 to use PrintStackIfFailedV() instead.

Hmm.. yes it does looks like PrintStackIfFailedV would be the correct thing to call here. Otherwise are we not making a vector of a vector? It seems like PrintStackIfFailed should be called only with individual types as arguments.

@mjbshaw
Copy link
Contributor Author

mjbshaw commented Jun 22, 2024

yes it does looks like PrintStackIfFailedV would be the correct thing to call here.

Okay, I've updated the PR to instead directly call PrintStackIfFailedV.

Otherwise are we not making a vector of a vector?

There's only a single argument in the variadic template, so {args...} desugars to {arg}, where arg is a vector derived from the sig argument. This form of braced initialization in this situation does not try to create a vector-of-vectors.

It seems like PrintStackIfFailed should be called only with individual types as arguments.

Yeah that seems to be the intention.

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Can you update the PR description and title?

I wonder if we could add some type checking to PrintStackIfFailed such that it verifies that each its arguments is indeed a Type? (and not come more complex type like this)?

@mjbshaw mjbshaw changed the title Pass args by reference to PrintStackIfFailed Avoid creating temporary vector copies when checking signature Jun 23, 2024
@mjbshaw
Copy link
Contributor Author

mjbshaw commented Jun 23, 2024

Can you update the PR description and title?

Done.

I wonder if we could add some type checking to PrintStackIfFailed such that it verifies that each its arguments is indeed a Type? (and not come more complex type like this)?

I've added a static_assert that enforces this (and confirmed it works as intended).

@sbc100 sbc100 merged commit f820d17 into WebAssembly:main Jun 24, 2024
18 checks passed
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.

None yet

2 participants