Bug 1635783 - Add a fast path for stack normalization. r=rhunt

Stack normalization is uber-slow on emulator because it relies on
regexes that are compiled to native instructions which are then
emulated.  That makes stack normalization very slow too, and as it's
very hot some tests will time out nearly always.

This patch inserts a simple cache for previously matched strings in
stack normalization to avoid the regex engine altogether.  This speeds
up normalization and hence stack matching greatly (I observed a factor
of four speedup per test iteration on an arm-sim noopt debug build for
ion-error-ool.js).

I also attempted some other fixes (filtering on simple strings,
avoiding regex.replace, etc) but caching is by far the most effective
fix, and with caching in place the other fixes still don't really move
the needle.

Depends on D74220

Differential Revision: https://phabricator.services.mozilla.com/D74607
This commit is contained in:
Lars T Hansen 2020-05-11 14:30:44 +00:00
Родитель cf386712a1
Коммит 43173e9f50
1 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@ -190,6 +190,12 @@ const WasmHelpers = {};
WasmHelpers.isSingleStepProfilingEnabled = enabled;
})();
// The cache of matched and unmatched strings seriously speeds up matching on
// the emulators and makes tests time out less often.
var matched = {};
var unmatched = {};
WasmHelpers._normalizeStack = (stack, preciseStacks) => {
var wasmFrameTypes = [
{re:/^jit call to int64 wasm function$/, sub:"i64>"},
@ -215,13 +221,24 @@ WasmHelpers._normalizeStack = (stack, preciseStacks) => {
var framesIn = stack.split(',');
var framesOut = [];
outer:
for (let frame of framesIn) {
if (unmatched[frame])
continue;
let probe = matched[frame];
if (probe !== undefined) {
framesOut.push(probe);
continue;
}
for (let {re, sub} of wasmFrameTypes) {
if (re.test(frame)) {
framesOut.push(frame.replace(re, sub));
break;
let repr = frame.replace(re, sub);
framesOut.push(repr);
matched[frame] = repr;
continue outer;
}
}
unmatched[frame] = true;
}
return framesOut.join(',');