-
Notifications
You must be signed in to change notification settings - Fork 108
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
read: add Dwarf::populate_abbreviations_cache #679
Conversation
Yep, about the same performance. The I'd document that Thanks for working on this, and for making this library! Some theoretical thoughts, optional reading: The LazyArc's behavior under contention is not ideal: if multiple threads try to get the same abbreviations at the same time, they'll all do the parsing, and all but one will discard the result. It would be better (?) if one thread did the parsing while other threads wait. A busy-wait seems good enough and easy to implement by making the LazyArc's atomic have 3 states: empty, busy, ready. Busy-wait seems better than duplicate work because: (a) it will complete sooner because it only waits for the remaining fraction of the work, (b) it can do something like thread::yield_now(), (c) it doesn't read from the Reader. The downside is that it's not lock-free, i.e. we'd be in trouble if the thread dies or stalls in the middle of parsing abbreviations. Threads dying or stalling is not a real concern in practice (or is it?) (except for panics, but they can be handled by just resetting the LazyArc state to 'empty'), so busy-wait seems better overall. Since |
Thanks for the feedback.
Note that this only happens for
I'm starting to question the value of using The original reason for |
Ah, I didn't notice that.
I agree. Maybe the behavior should be:
Fwiw, for me the abbreviations cache stood out as a surprising behavior: in a mostly straightforward low-level library that just parses bytes when requested, there's this one place where it does nontrivial things behind the scenes: caching (imposing memory usage), reference counting, thread synchronization, none of that mentioned in the documentation for |
Sounds good. I've added a commit to do that. |
The code looks good to me, performance on my test is still good. |
c8c3864
to
77dd7a2
Compare
This gives additional options for caching duplicate entries or all entries.
@al13n321 Can you test if this has similar performance to the caching you implemented?