-
Notifications
You must be signed in to change notification settings - Fork 53
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
Large tuples are a performance footgun #237
Comments
I wonder if #251 improved the situation as the compiler is now more likely to optimize the tuple version into the imperative version. |
@martinohmann when you have more time, could you create a branch where hcl-edit is using tuples so I can do some more analysis of this? I'd like to see how #251 or tuple alternatives may be able to help improve things. Because of the chance of this being fixed in #251, I'm deprioritizing this for now, so no rush. |
Good idea! I'll try find some tuple cases. The parser is built in a way now that makes bringing these back a bit more involved. But I think I see 1-3 cases that are "easy" to negatively impact performance. Not sure if I can get to it this month or next month. Will ping you once I have a branch. |
@praveenperera in #191 (comment)
|
That AI answer has a semblance of sounding correct but is completely wrong.
The answers for when to make individual |
If you use If you have a function like fn add(left: usize, right: usize) -> usize {
left + right
} the compiler will effectively transform this to fn add(left: usize, right: usize, out result: usize) {
out = left + right
} The fastest form of memory is called a register and parameters and return types go through these where possible. However, if a parameter or return type becomes too big, the compiler will instead return through the stack which is using memory (with dcaches), turning it into fn add(left: &Large, right: &Large, result: &mut Large) {
*out = left + right
} Before v0.5, winnow's return type was Result<
(I, O),
ErrMode<InputError<I>>,
> Meaning that Winnow <=v0.4 added Now that we use Result<
O,
ErrMode<ContextError>,
> Winnow has a fixed overhead for error reporting (reducable by specifying a custom error type) but the However, if you do In general, write your code for readability and if its too slow, experiment. It can be surprising what things can speed up or slow things down as there are ripple effects in optmizations. I tried to reduce shuffle things owe I had fewer large return types and instead I made performance worse. |
@epage very detailed and very helpful thank you! You should add their comments to the docs. One more question :
That is still the return type for Thanks again updateFor anyone reading this, here is an example of switching from |
As mentioned on the other thread, |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
#505 moves |
Please complete the following tasks
rust version
1.68
winnow version
0.4.0
Minimal reproducible code
Steps to reproduce the bug with the above code
TBD
Actual Behaviour
Slow
Expected Behaviour
Fast
Additional Context
See #230
Options
The text was updated successfully, but these errors were encountered: