adamrk removed the review request for wasmtime-core-reviewers from PR #15145.
adamrk opened PR #15145 from adamrk:abk/elide-reader-typecheck-followup to bytecodealliance:main:
When a
StreamReader<T>orFutureReader<T>is lowered into a guest,typecheck_lowered_transmitchecks the transmit's origin against the destination payload type. The typeThas already been checked against the payload type, so this change allows the dynamic check to be elided in the cases when we can rely on the static check that was already done.There are 3 cases to consider:
A
StreamReader<T>was directly created in the host by aProducerwithP::Item == T. This case is marked with a bool tag in theHostResourceIndexand no further checks are needed.A
StreamReader<T>was created by the host, but has been passed through a guest and may have had its type loosened (e.g. aStreamReader<StreamReader<String>>became aStreamReader<StreamAny>). In this case, we compare theTypeIdof the Producer'sP::ItemagainstTand skip further checks if they match. If they don't match we dynamically run the Producer'stypecheck.A
StreamAnyalways runs the dynamic typecheck.This shows a ~5% improvement in the
p3_http_proxybenchmark:Main (8c11e2e0edbd344886b6daab87aba5eb3a6e5ca9):
wasi-http/p3_http_proxy time: [17.731 µs 17.751 µs 17.780 µs] Found 5 outliers among 100 measurements (5.00%) 1 (1.00%) high mild 4 (4.00%) high severe wasi-http/p3-api/request.new time: [1.4515 µs 1.4536 µs 1.4561 µs] Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) high mild 1 (1.00%) high severe wasi-http/p3-api/response.consume-body time: [2.1158 µs 2.1311 µs 2.1449 µs] Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high severe wasi-http/p3-api/client.send time: [2.9556 µs 2.9614 µs 2.9667 µs] Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high mildBranch:
wasi-http/p3_http_proxy time: [16.834 µs 16.858 µs 16.890 µs] change: [−5.2232% −5.0299% −4.8189%] (p = 0.00 < 0.05) Performance has improved. Found 5 outliers among 100 measurements (5.00%) 1 (1.00%) high mild 4 (4.00%) high severe wasi-http/p3-api/request.new time: [1.1689 µs 1.1733 µs 1.1805 µs] change: [−19.787% −19.146% −18.210%] (p = 0.00 < 0.05) Performance has improved. Found 8 outliers among 100 measurements (8.00%) 2 (2.00%) low mild 4 (4.00%) high mild 2 (2.00%) high severe wasi-http/p3-api/response.consume-body time: [1.7009 µs 1.7146 µs 1.7300 µs] change: [−19.751% −18.733% −17.645%] (p = 0.00 < 0.05) Performance has improved. Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high severe wasi-http/p3-api/client.send time: [2.9678 µs 2.9714 µs 2.9746 µs] change: [+0.1770% +0.5625% +0.9582%] (p = 0.01 < 0.05) Change within noise threshold. Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high mild<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
adamrk requested cfallin for a review on PR #15145.
adamrk requested wasmtime-core-reviewers for a review on PR #15145.
:speech_balloon: adamrk created PR review comment:
Note: I'm a bit worried that sticking this tag in the
HostResourceIndexcould cause problems later since we don't have anything in the type system indicating that the tags exist. It seems to be worth about 1.5% of the overall 5% improvement in the http proxy benchmark, so I'm not really sure if it's worth it. I also tried just using a separate bool, but that seems to be a wash overall.So I think we could remove the take and loose the fastest
Elidedpath altogether, or maybe if we think index tagging could be useful in general it might make sense to introduce it into the types and use it here.
:memo: adamrk submitted PR review.
github-actions[bot] added the label wasmtime:api on PR #15145.
adamrk updated PR #15145.
alexcrichton removed the review request for cfallin from PR #15145.
alexcrichton requested alexcrichton for a review on PR #15145.
:memo: alexcrichton submitted PR review:
This seems reasonable to me yeah, but I'm curious if we can remove one of the variants of
TransmitCheckif it's not needed for performance.Otherwise though I think it'd be good to have some docs somewhere explaining the situation a bit more as well. Maybe on
fn transmit_checkor maybe onfn run, I'm not sure which. The general idea though is thatT::typecheckhas already run at some point and the second-layer of checking here is basically "is there more needed than that". I'm getting lost myself a bit in this, so I'm not entirely sure what such a comment would say though. For example loweringStreamReader<StreamAny>to a guest doesn't type-check further thanstream<stream<?>>in thetypecheckimplementation up-front, but then sending aStreamAnyon that stream does indeed type-check the?.I guess maybe I'm just a bit lost. Can you describe a bit more the situations where this is applying? For example what I can see is that if you create
StreamReader<u8>then this is skipping atypecheckagainstInterfaceType::U8which, while fast in theory, still involves some lookups and dynamic dispatch. I don't fully understand theStaticvsElideddistinction though...
:speech_balloon: alexcrichton created PR review comment:
For the benchmarks that you're looking at, is this case needed? I feel like this PR would be simpler without this, but if it's needed for performance then it's needed
:speech_balloon: alexcrichton created PR review comment:
Personally I'd lean towards an auxiliary
boolrather than a tag bit given the usage of this index for other purposes too
adamrk updated PR #15145.
adamrk commented on PR #15145:
Sorry, I got distracted by some other stuff and took a while to get back to this. I've reworked it to just have the auxiliary boolean and I've added comments to clarify the invariant and why we can skip the typecheck when lowering the read end of a future/stream when the boolean is set.
Here are the benchmark numbers for the latest version:
Main (
68f6475eac03b53a863c3e9c83ec587265fc70a4)wasi-http/p3_http_proxy time: [18.869 µs 18.887 µs 18.916 µs] Found 7 outliers among 100 measurements (7.00%) 2 (2.00%) high mild 5 (5.00%) high severe wasi-http/p3-api/request.new time: [1.6562 µs 1.6658 µs 1.6826 µs] Found 4 outliers among 100 measurements (4.00%) 1 (1.00%) low mild 1 (1.00%) high mild 2 (2.00%) high severe wasi-http/p3-api/response.consume-body time: [2.4195 µs 2.4584 µs 2.5194 µs] Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high severe wasi-http/p3-api/client.send time: [3.0056 µs 3.0090 µs 3.0123 µs] Found 1 outliers among 100 measurements (1.00%) 1 (1.00%) high severeBranch
wasi-http/p3_http_proxy time: [17.774 µs 17.796 µs 17.829 µs] change: [−5.9549% −5.6885% −5.3230%] (p = 0.00 < 0.05) Performance has improved. Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe wasi-http/p3-api/request.new time: [1.3877 µs 1.4049 µs 1.4269 µs] change: [−16.860% −16.201% −15.506%] (p = 0.00 < 0.05) Performance has improved. Found 6 outliers among 100 measurements (6.00%) 1 (1.00%) low mild 1 (1.00%) high mild 4 (4.00%) high severe wasi-http/p3-api/response.consume-body time: [2.0159 µs 2.0631 µs 2.1249 µs] change: [−18.473% −17.073% −15.637%] (p = 0.00 < 0.05) Performance has improved. Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high severe wasi-http/p3-api/client.send time: [2.9696 µs 2.9743 µs 2.9792 µs] change: [−1.3104% −1.0455% −0.7862%] (p = 0.00 < 0.05) Change within noise threshold. Found 6 outliers among 100 measurements (6.00%) 5 (5.00%) high mild 1 (1.00%) high severe
adamrk requested alexcrichton for a review on PR #15145.
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #15145 Elide redundant typecheck when lowering readers to the merge queue.
:check: alexcrichton merged PR #15145.
alexcrichton removed PR #15145 Elide redundant typecheck when lowering readers from the merge queue.
Last updated: Nov 19 2026 at 20:05 UTC