Commit 65e9297
Add fast-path to ConfigPreprocessor::replaceParams for strings without parameters
Summary:
**This is a semi-automated perf-finding. I don't think this has huge impact given that config reloads are likely not very frequent, but it does have the nice benefit of making CPU less spiky when they do happen. I am happy to abandon or push, whichever the team prefers. This is however quite simple for a little savings.**
Strobelight profiling of edgeray/originray shows `ConfigPreprocessor::replaceParams` consuming ~1.8% exclusive CPU during config reloads (https://fburl.com/scuba/strobelight_services/zg0oj1mq).
The `replaceParams` function processes every string value in the mcrouter config JSON, scanning character-by-character via `unescapeUntil` looking for `%param%` substitutions. Most config strings do not contain parameter references or escape sequences, but the function still processes them character-by-character.
This adds a fast-path check at the top: if the string contains neither `%` nor `\`, return it immediately. `StringPiece::find` uses `memchr` which is highly optimized (SIMD on x86), making this check much faster than the character-by-character loop.
Combined with `ConfigPreprocessor::Context::add` (1.0%) and `Context::~Context` (1.0%), config preprocessing accounts for ~3.8% of total CPU. This fast-path reduces the `replaceParams` contribution for strings without parameters.
Reviewed By: stuclar
Differential Revision: D95426937
fbshipit-source-id: 329428d92aa7cbf617d791edbc6b5207580ad65d1 parent 3828a2b commit 65e9297
1 file changed
+8
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1828 | 1828 | | |
1829 | 1829 | | |
1830 | 1830 | | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
1831 | 1839 | | |
1832 | 1840 | | |
1833 | 1841 | | |
| |||
0 commit comments