Closed jszwedko closed 1 year ago
This is low priority, but just figured I'd record it.
contains
is another one.
I suspect that there are a number of functions in Remap that do try_bytes_utf8_lossy().into_owned()
that with a bit of refactoring could avoid the clone. It would be a useful exercise now that we have some good benchmarks to look through each function and see what could be enhanced. The cost would likely be increased code complexity.
Adding this to the backlog, as a generic "remove any unneeded string allocations" ticket, starting with the above-mentioned functions.
Closing as at least partially addressed by https://github.com/vectordotdev/vector/pull/10296. We can let user demand drive further improvements.
While optimizing a user script:
The question of whether the
starts_with
guard was useful in reducing the performance impact of just callingparse_json
all the time. Running a quick benchmark makes it seem like this is not the case:Diff of the benches I added:
My best guess for this is because we always convert the value and substring to UTF-8 via
try_bytes_utf8_lossy
for the comparison. I think we can probably implement these two functions without converting the bytes to a string and instead just compare them as-is.