log icon indicating copy to clipboard operation
log copied to clipboard

Target maybe static

Open jelmansouri opened this issue 3 years ago • 2 comments

Our telemetry module, enables us to pool static strings and send them once instead of copying and writing a string at each log line. The target is part of the information that gets sent to do additional filtering when logs are consumed. The goal is to introduce this optimization without breaking the public API, so we can benefit from the optimization in all of our dependencies. The code is less DRY than I would have hoped so I'm very open to suggestions regarding how to write this is a better fashion!

jelmansouri avatar Dec 15 '21 17:12 jelmansouri

Regarding the MSRV, the additional code is a further optimization in cases like info!(target: "my_target", "my log line") I can either remove it or try some trickery with cfg(version("1.when_it_was_introduced")). Maybe overkill and we can revisit when the MSRV is bumped.

jelmansouri avatar Dec 15 '21 17:12 jelmansouri

Thanks for your patience and for working on this one @jelmansouri! It's a bit unfortunate that

info!(target: static_str(), "Some message");

won't produce a static target, since it won't match the literal arm in the macro. Before accepting this I think I'd like to see some more exploration of the motivations and your specific use-case, what lead to this particular approach, and what its benefits and drawbacks are. If you're already pooling static strings then a single allocation to convert any &str into owned Strings the first time you see them doesn't sound prohibitive to me, but you might have already been down that path 🙂

KodrAus avatar Jan 17 '22 01:01 KodrAus