Closed Hywan closed 7 years ago
Bench results.
Before:
test rules::literals::tests::bench_simple ... bench: 2,939 ns/iter (+/- 1,086)
After:
test rules::literals::tests::bench_simple ... bench: 2,792 ns/iter (+/- 548)
tested with a string of size 5k. This is a boost of 5%.
For smaller strings of size 12 bytes, the boost is of 20%. Well, the benchmarks are less relevant in this case. I have done 10 runs, and the boost is constantly about 20%.
For escaped strings, so with a copy, strangely these is a constant boost of 1-2%. I don't know why, but I take it.
A string is no longer copied by default. A single quoted string is copied if and only if it contains an escaped character, because the resulting string must not contain the escaping character, and this is not possible to concatenate slices, so the new string is copied inside a
Vec<u8>
. However, if no character is escaped, or if it is a nowdoc string, there is no longer any copy.Behind the scene, we use a clone-on-write smart pointer:
std::borrow::Cow
.A benchmark needs to validate this work though, but I am confident it will improve the global performance, let's see.
Interesting commits are:
cc @jubianchi @Geal