-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Box error values in Results #7346
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
Box error values in Results #7346
Conversation
Edit: I take it all back - this change is actually needed for #6833. That PR introduces In other words, if we want to generate good diagnostics, shaving off a few Original comment: This was a bit stubborn of me. I'm happy to listen to the preferences of active Naga contributors as to whether this is actually desirable or not. My rationale:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one issue
before approving (as a conversation item against the diff).
praise: It does seem like the move to a Box
is important, esp. if your motivation is to avoid creating very large errors in your work in #6443.
nitpick: I'm not sure that the change from Box<str>
is well enough motivated to convince me that we can accept memory pressure for the sake of simplicity when we are considering issues like #5295. Aggregate size of Error
s can still matter once we move to an architecture that gathers errors instead of necessarily changing control flow, and might not return before gathering quite a lot of them. I'd prefer to break this change out to something separate, and maybe decouple it from your current commit stack.
Still, we don't have benchmarks governing this, so I don't see it as a blocking issue, regardless of how I feel.
I used Conventional Comments in this review! I hope they help with clarity and tone. 🙂
Introduce a new type alias, `naga::front::wgsl::Result`, that is `core::result::Result` with the error type fixed to `naga::front::wgsl::Error`. Use this alias where appropriate. This commit should cause no changes in behavior or interface.
Change the definition of `naga::front::wgsl::Result` to carry a boxed `Error`, so that the size of `Error` does not affect performance of success paths.
Use `String` in variants of `naga::front::wgsl::Error`, not `Box<str>`. Delete test `naga::front::wgsl::error::test_error_size`. Since `Error` is always returned boxed, its size should have no effect on `Result` size.
025b185
to
58e2d22
Compare
Using |
Thank you! But that is not my motivation. Out of habit, I used the summary of my last commit as the title of the PR, but the current title does not properly explain why this change is needed. The problem is that large error types make for large result types, which affect the performance of every function call that uses them, regardless of whether or not an error occurs. I would actually like to be free to build quite large error types. |
String
in error, not Box<str>
.
Okay, the original PR, #6146, was concerned with another angle I hadn't considered, which was stack usage. However, that PR claims that boxing reduced performance by 2%, which I find hard to believe. |
Here's what I'm seeing from this PR:
This doesn't seem like a blocking concern. |
I certainly want to see Naga producing multiple errors per compilation, like any respectable compiler. But I think we should agree that once we've produced, say, 1000 error messages, we've gone far beyond anything that would be valuable to a user. We probably want to cap the number of errors we produce before giving up at around 100 or so. That suggests that individual error records could be tens of kilobytes in size and still only use a megabyte, which is hardly prohibitive. (After all, if Naga had succeeded in generating output, we would have passed the shader along to the GPU driver's compiler...) So I'm just not convinced that the size of |
I measured how much stack space the
So this PR is better at addressing stack size concerns than the PR that replaced |
What I mean by "large errors" is "large errors on the stack". So, I think we're in violent agreement there. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the discussion that was valuable for this PR has been had, and I don't see any blockers.
Use
String
in variants ofnaga::front::wgsl::Error
, notBox<str>
.Change the WGSL front end to always return
Error
values boxed, so that the size ofError
does not affect the performance of success paths. This reduces the minimum size ofResult
s in the WGSL front end from 48 bytes to 8.Delete test
naga::front::wgsl::error::test_error_size
. SinceError
is always returned boxed, its size should have no effect onResult
size.