The updated code is designed to: - Be branch-predictor-friendly - Be cache-friendly - Minimize the lengths of critical paths - Minimize slow operations (particularly multiplications) - Minimize binary/codegen bloat The most notable performance trick here is perhaps the precomputation & caching of the number of digits, so that we can reuse/exploit it when writing the output. This precomputation of the exact length enables 2 further performance benefits: - It makes `StrCat` and `StrAppend` zero-copy when only integers are passed, by avoiding intermediate `AlphaNum` entirely in those cases. If needed in the future, we can probably also make many other mixtures of non-integer types zero-copy as well. - It avoids over-reservation of the string buffer, allowing for more strings to fit inside SSO, which will likely have further performance benefits. There is also a side benefit of preventing `FastIntToBuffer` from writing beyond the end of the buffer, which has caused buffer overflows in the past. The new code continues to use & extend some of the existing core tricks (such as the division-by-100 trick), as those are already efficient. PiperOrigin-RevId: 595785531 Change-Id: Id6920e7e038fec10b2c45f213de75dc7e2cbddd1
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| internal | Loading commit data... | |
| BUILD.bazel | Loading commit data... | |
| CMakeLists.txt | Loading commit data... | |
| attributes.h | Loading commit data... | |
| bit_cast_test.cc | Loading commit data... | |
| call_once.h | Loading commit data... | |
| call_once_test.cc | Loading commit data... | |
| casts.h | Loading commit data... | |
| config.h | Loading commit data... | |
| config_test.cc | Loading commit data... | |
| const_init.h | Loading commit data... | |
| dynamic_annotations.h | Loading commit data... | |
| exception_safety_testing_test.cc | Loading commit data... | |
| inline_variable_test.cc | Loading commit data... | |
| inline_variable_test_a.cc | Loading commit data... | |
| inline_variable_test_b.cc | Loading commit data... | |
| invoke_test.cc | Loading commit data... | |
| log_severity.cc | Loading commit data... | |
| log_severity.h | Loading commit data... | |
| log_severity_test.cc | Loading commit data... | |
| macros.h | Loading commit data... | |
| no_destructor.h | Loading commit data... | |
| no_destructor_benchmark.cc | Loading commit data... | |
| no_destructor_test.cc | Loading commit data... | |
| nullability.h | Loading commit data... | |
| nullability_test.cc | Loading commit data... | |
| optimization.h | Loading commit data... | |
| optimization_test.cc | Loading commit data... | |
| options.h | Loading commit data... | |
| policy_checks.h | Loading commit data... | |
| port.h | Loading commit data... | |
| prefetch.h | Loading commit data... | |
| prefetch_test.cc | Loading commit data... | |
| raw_logging_test.cc | Loading commit data... | |
| spinlock_test_common.cc | Loading commit data... | |
| thread_annotations.h | Loading commit data... | |
| throw_delegate_test.cc | Loading commit data... |