Commit ee168e7
authored
Change the internal structure of JsString for performance (#4455)
This is the first in a series of PR to improve the performance of
strings in Boa.
The first step was to introduce a new type of strings, `SliceString`,
which contains a strong pointer to another string and start/end indices.
This allows for very fast slicing of strings. This initially came at a
performance cost by having an enumeration of kinds of strings. An
intermediate experiment was introduced to have the kind be a tag on the
internal JsString pointer. This still came as a cost as it required bit
operations to figure out which function to call.
Finally, I moved to using a `vtable`. This helped with many points:
1. as fast as before. Before this PR, there was still a deref of a
pointer when accessing internal fields.
2. we can now introduce many other types (which will come in their
separate PRs).
3. this makes the code to clone/drop/as_str (and even construction) more
streamline as each function is their own implementation.
The biggest drawback is now we are operating with a bit more pointer and
unsafe code. I made sure that all code was passing both debug, release
and miri tests on boa_string and boa_engine's builtins::string suite.
This `vtable` bring slightly better performance (depending on the test,
about 90-110%, but overall 2-3% better than the `main` branch), even
though we only directly improved string slicing operations.
The next suite of PRs are going to cover more string types:
1. since strings are constant and unmutable, include the length in the
vtable directly instead of relying on a function call.
2. also because of the above, splitting latin1 and utf-16 string kinds
to remove conditionals on a lot of sub functions.
3. have a concat string that makes concatenation instant, similar to how
slice improve concatenation
Also, there might still be some slicing that creates new strings from
existing ones without using SliceString. Those can be improved greatly.
Please note the `benches/scripts/strings/slice.js` test is twice as fast
with this branch than with `main`.
The performance table for this PR:
| Test | Main | PR |
|---|-----|-----|
| Richards | 218 | 233 |
| DeltaBlue | 234 | 244 |
| Crypto | 184 | 208 |
| RayTrace | 502 | 485 |
| EarleyBoyer | 595 | 584 |
| RegExp | 88.1 | 83 |
| Splay | 905 | 837 |
| NavierStokes | 413 | 467 |
|---| --- | --- |
| TOTAL | 313 | 320 |1 parent 14e5c63 commit ee168e7
File tree
22 files changed
+1626
-1014
lines changed- benches
- benches
- scripts/strings
- src
- core
- engine/src
- builtins/string
- object/internal_methods
- value/inner
- string/src
- vtable
22 files changed
+1626
-1014
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
22 | | - | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
| 787 | + | |
| 788 | + | |
788 | 789 | | |
789 | 790 | | |
790 | 791 | | |
| |||
1887 | 1888 | | |
1888 | 1889 | | |
1889 | 1890 | | |
1890 | | - | |
| 1891 | + | |
| 1892 | + | |
1891 | 1893 | | |
1892 | 1894 | | |
1893 | 1895 | | |
| |||
1983 | 1985 | | |
1984 | 1986 | | |
1985 | 1987 | | |
1986 | | - | |
| 1988 | + | |
1987 | 1989 | | |
1988 | 1990 | | |
1989 | 1991 | | |
| |||
2002 | 2004 | | |
2003 | 2005 | | |
2004 | 2006 | | |
2005 | | - | |
| 2007 | + | |
2006 | 2008 | | |
2007 | 2009 | | |
2008 | 2010 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
567 | | - | |
| 567 | + | |
| 568 | + | |
568 | 569 | | |
569 | 570 | | |
570 | 571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
| 58 | + | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
0 commit comments