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

Reduce size of parse error #6146

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Reduce size of parse error #6146

merged 1 commit into from
Aug 27, 2024

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Aug 23, 2024

Description
Reduces size of parse error from 112 bytes to 48 bytes. This should help with stack usage during parsing, which is especially important given the huge warning about heavy stack usage.

Testing
There's a test asserting the new size.

It has a noticeable performance improvement:

front/shader: wgsl-in   time:   [5.3159 ms 5.3196 ms 5.3245 ms]
                        thrpt:  [291.07 MiB/s 291.34 MiB/s 291.54 MiB/s]
                 change:
                        time:   [-6.7480% -4.1415% -1.9554%] (p = 0.00 < 0.05)
                        thrpt:  [+1.9944% +4.3204% +7.2363%]
                        Performance has improved.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
  • Run cargo xtask test to run tests.

@kornelski kornelski requested a review from a team August 23, 2024 14:17
Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

I'm open to this sort of change, but I noticed a couple of things that I think need to change with this before merges.

I also want to confirm with @teoxoy and/or @jimblandy that this is a desirable change. I suspect that it might get rejected unless we can justify a quantitative gain here in terms of our own benchmarks (which should be easy?). @kornelski: Does this empirically reduce a memory high mark, or improve run times?

@ErichDonGubler ErichDonGubler self-assigned this Aug 23, 2024
@ErichDonGubler ErichDonGubler requested a review from a team August 23, 2024 15:17
@ErichDonGubler ErichDonGubler added lang: WGSL WebGPU Shading Language area: performance How fast things go naga Shader Translator area: naga front-end labels Aug 23, 2024
@kornelski
Copy link
Contributor Author

It reduces stack usage of too_many_unclosed_loops test (#5447) from 1.6MB to under 1MB.

@teoxoy
Copy link
Member

teoxoy commented Aug 23, 2024

How does this compare with boxing the error type itself? Maybe it can be done non-invasively via a newtype.

Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

My concerns have been resolved. I will defer to the rest of @gfx-rs/naga for merging.

@kornelski
Copy link
Contributor Author

kornelski commented Aug 23, 2024

@teoxoy I've tried boxing errors. It decreases perf by 2%, and the change is way more invasive — needs changing all return types, all return Err expressions, and closures using ? need type hints added.

There are some functions that match on the errors, so to avoid boxing, unboxing, and boxing again, they need to keep returning the unboxed error.

kornelski@c414134

@teoxoy
Copy link
Member

teoxoy commented Aug 27, 2024

I see, thanks for giving it a shot! I think we can land this.

@teoxoy teoxoy merged commit c7e5d07 into gfx-rs:trunk Aug 27, 2024
25 checks passed
@kornelski kornelski deleted the parse-err-size branch August 27, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end area: performance How fast things go lang: WGSL WebGPU Shading Language naga Shader Translator
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants