Skip to content
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

{msg} .set_message(Cow<'static, str>) design unnecessarily requires allocation #615

Open
JulianKnodt opened this issue Dec 20, 2023 · 3 comments

Comments

@JulianKnodt
Copy link

JulianKnodt commented Dec 20, 2023

Currently I want to display a float adjacent to the progress bar (for reference it's essentially an optimization loss).

Right now, I have to do {msg} in the style, and later .set_message(format!("{:.03e}", float)). It's a hyper optimization, but because I'm calling format! every iteration, I'm allocating a String every loop. Is it possible to have a function that instead takes an Arguments struct, thus (I think) removing the allocation?

Willing to figure out how to submit a PR if so

@JulianKnodt JulianKnodt changed the title {msg} .set_message(Cow<'static, str>) is too restrictive {msg} .set_message(Cow<'static, str>) design unnecessarily requires allocation Dec 20, 2023
@djc
Copy link
Collaborator

djc commented Dec 20, 2023

So are you updating the message on every iteration of a hot loop? Maybe it's feasible to use a ProgressTracker impl instead?

@JulianKnodt
Copy link
Author

Right now I'm displaying [Elapsed/ETA] {progress bar} {current iter}/{total iters}{msg}. I now only update the msg every Nth iteration, which is alright.

I don't see a ton of docs for the progress tracker (I didn't even know it existed). If I want to use that, do I have to drop a lot of existing functionality?

@djc
Copy link
Collaborator

djc commented Dec 21, 2023

Uh, no? The ProgressTracker can be used to define a custom key for use in a format string, so you can do whatever you need with your float and only have it format whenever indicatif is drawing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants