-
Notifications
You must be signed in to change notification settings - Fork 11
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 expensive clones in loop #202
Comments
So, just skimming the docs, one of the sins of these calls to |
The title makes I believe there is a reference implementation that should be consulted in terms of performance to validate there was no regression. I'd use hyperfine for that.
Performance is part of the value proposition and thus I think it's critical to protect it from regressions. Criterion can also be used for microbenchmarks, it will neatly display the difference between runs so regressions, or improvements, become evident quite clearly. |
Sorry if I made it sound like Thanks for recommending |
Results of
Where |
Thanks for the numbers! There definitely is a lot of performance to be had by avoiding clones in a tight loop.
There is no |
Got it, updated the description. But these |
They have state, but it's not a cache. Maybe it's just terminology though, as one can probably see all state as cache if one wanted to as long as one is able to set the state to the point where it's needed to get the correct response, albeit much more expensively. |
Got it, thanks! Yeah, I could've used clearer wording -- state would be the more appropriate word. |
Note-to-self: I'm not really fond of |
@Byron sorry for bugging you again, but I was looking at the Which of these is
I was reading it as the former for a while. That is, a state that is created once per thread. But I'm thinking that interpretation was probably incorrect, and as a result I was misunderstanding the intent of the code you authored (#200 (comment)). |
It's state created once per thread and passed mutably to |
Got it. Yeah, with your comment and by reviewing the source code I think it's clear now. My naive and incorrect assumption was that a thread was spawned per item in the slice, when in reality Since a lot of the logic isn't specific to |
That may sound harsh, but the answer is: "Definitely not" :D. The reason for this is that it's a couple of lines that can easily be copied to where they are needed, along with the adjustments that are typically needed as well. I keep modifying how these utilities work and experiment with them until maybe they turn out to remain stable because they work for my usecases. I'd consider them basic and (except for the slice-based version of it) potentially problematic as the chunk-based forms don't do work-stealing. Other approaches can be better, but The beauty here really is that thanks to Rust it's easy to come up with simpler primitives that still work well enough most of the time, while letting them fit on a screen. There is also no |
You're reminding me of |
The worktree stack and outcome of attr matches is getting cloned per path/entry, which, as @Byron pointed out in #200, is not the intended usage. Also, a thread-local repository shouldn't be created per-path.
This will almost unavoidably change some immutable values to mutable refs, which will be reflected upstream in the implemented trait. This will count as a breaking change due to the public trait's required method signatures changing.
Edit 2023/10/09:
Perhaps a
FileSource
could implement a method that returns a mutable thread state.The text was updated successfully, but these errors were encountered: