Bug 1873042 - Part 8: Optimise single- and two-character strings for LSubstr. r=jandem
commitf8a95cb28f6538aa1300a1219808cd997cd30bdb
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 10 Jan 2024 15:14:21 +0000 (10 15:14 +0000)
committerAndré Bargull <andre.bargull@gmail.com>
Wed, 10 Jan 2024 15:14:21 +0000 (10 15:14 +0000)
treeff161c01f3b07079ab3c64e36a40ac22dfdea27c
parenta82cf5307b2660ea16cc46f4edd7c542c2d7a230
Bug 1873042 - Part 8: Optimise single- and two-character strings for LSubstr. r=jandem

It's always a bit confusing when benchmarking `LSubstr` to see slow downs for
µ-benchmarks like:
```
for (let i = 0; i < N; ++i) {
  r += xs[i&1].substring(0, 2).length;
}
```

because when the inlined allocation for `JSThinInlineString` fails because the
nursery is full, we fall back into the VM. The VM code prefers to use the shared
static two-elements strings, so there's no GC which can clear up the nursery. We
jump back into the generated JIT code and in the next loop iteration we again fall
back into the VM, because the nursery is still full, since no GC happened.

Adding support for two-element string lookups avoid this issue.

Differential Revision: https://phabricator.services.mozilla.com/D197693
js/src/jit-test/tests/warp/string-substring-static-strings.js [new file with mode: 0644]
js/src/jit/CodeGenerator.cpp
js/src/jit/LIROps.yaml