-
Notifications
You must be signed in to change notification settings - Fork 97
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
Provide Way to Avoid Allocating To Collect Formatting Errors #323
Comments
I might be interested in contributing for this if it's something you guys are interested in. |
For the errors - we could swap to accept a mutable reference to a trait object that implements For args - this is a bit more tricky. I'm not sure if an iterator is actually saving us here, and I suspect it would incur a perf penalty. What we could do, again, is swap it for a trait that you can implement for Vec, HashMap, and your own type. I'm open to PRs! |
Oh, good idea, I didn't think of using trait objects! I think I'll try that out if I get the chance and open a PR if it looks like it works. |
@zicklag Did you by any chance get an opportunity to experiment with this? |
No I didn't, and I probably won't end up being able to any time soon, though it's still something I'd like to come back to eventually. |
Fair enough, I was just doing triage and wondered if there was anything out there to review, whether this was still something desired or not, etc. |
This problem space is also covered in #254, but for different reasons. Given that any refactoring of this API surface should probably take both problems into account at once I'm going to close that issue as a duplicate of this one, but the issue/proposed fix is coming at this from a different angle than concurrency, so I'm duplicating the relevant discussion here: From @clarfonthey:
And from @gregtatum:
|
The
bundle.format_pattern()
method takes a&mut Vec<FluentError>
to allow you to respond to errors, but I have a situation where my bundle struct is accessed concurrently across multiple threads with just a read-only reference.I'm trying to avoid allocating every time I need to format a message. Usually, if I had mutable access, I'd just pre-allocate the vector for collecting the errors, and re-use that vector every time I format a message, but since I've only got concurrent access to my helper function for formatting, that isn't possible.
On thought is that I could pass in an
FnMut
closure that will be called every time there is an error. This would allow me to choose how I handle the error message without requiring an allocation.In this case, I simply wish to log the error using the
log
ortracing
crates.On a related note, I just noticed that
FluentArgs
also allocates since it contains aVec
. I wonder if we could make that an iterator or something like that. 🤔 If it was a double-ended iterator, then that would allow us to iterate back and forth through it to find the keys in it as needed.I'm using fluent for game development so avoiding allocations per-frame is really important where possible.
The text was updated successfully, but these errors were encountered: