Closed Bug 1687093 Opened 5 years ago Closed 5 years ago

Span's size takes 4 bytes for each delazification, even if it's empty

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
86 Branch
Tracking Status
firefox86 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 external file, 1 obsolete file)

raptor yahoo-mail's largest JS file's XDR contains ~4700 delazifications, and
each one takes 4 bytes to encode BigIntData.size() = 0
we should add single byte for each BaseCompilationStencil that describes which span isn't empty.
in most case regExpData.size() is also 0, and in some case objLiteralData.size() is also 0,
so we can compress up to 12 bytes into 1 byte.

other possibility is to use varint, even if the span isn't empty.
so that we can compress size data into 1 byte for each span, in most case.

because of alignment (align32) before span content, 1 byte before the alignment can become 4 bytes, (depending on the alignment before that)
so we should compress at least 5 bytes into 1 byte to get actual size reduction, consistently.

gathering flags and all sizes with varint before all spans' contents could help.

Blocks: 1687143
No longer blocks: 1609486
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

with the patch that adds flag, and then use varint for span/vector size, the size taken by XDR of raptor tp6 yahoo-mail mail_app_es6_09* JS file:

unpatched patched diff
Version 22 22 0
AtomTable 1,977,500 1,977,500 0
ImmutableScriptData 1,984,138 1,984,138 0
Scope 164,428 150,359 -14,069
ScopeName 212,848 194,040 -18,808
BigInt 18,808 0 -18,808
Object 180,382 163,231 -17,151
RegExp 19,320 544 -18,776
GCThingData 479,194 465,138 -14,056
ScriptData 765,064 750,966 -14,098
ScriptExtra 490,212 490,212 0
SharedData 4,702 4,702 0
Module 0 0 0
Source 3,071,613 3,071,613 0
Chunk 37,621 42,315 +4,694
Total 9,405,852 9,294,780 -111,072

To reduce the size taken by empty span's size, compress possibly-empty span's
info into single byte flag.

Because of alignment before span content, 1 byte flag could inflate to 4 bytes.
Use varint for all span/vector length and encode them before span, so that
the size reduction works more efficiently.

Depends on D102119

I'm wondering if instead of optimizing for optimal size in all cases, I wonder if we can instead focus on a few simple patterns and simplify the code.

// Leaf delazification. Implicitly, nscript = 1.
| 00000000 | nscope   | ngcthing | nobjlit  |

// All lists are 8-bit. I expect this is very common.
| 00000001 | nscope   | ngcthing | nobjlit  |
|          | nscript  | nbigint  | regexp   |

// Use flags for u32 lengths.
| XXXXXXX1 | nscope   | ngcthing | nobjlit  |
|          | nscript  | nbigint  | regexp   |
  ...
| <32-bit value for each flagged value>     |

What do you think? I expect it to be very effective since any Stencil that exceeds 256 in one dimension will have data much larger than any header. It should also be fast to decode and maintain u32 alignment.

u23 nscript = 1;
u32 nscope = ...;
u32 ngcthing = ...;
u32 nobjlit = ...;
u32 nbigint = 0;
u32 nregexp = 0;

if (flags) {
  nbigint = ...
  nregexp = ...

  if (flags > 0x1) {
    if (flags & 0x2) nscript = ...;
    ...
  }
}

Also, optimizing FunctionKey does seem worthwhile if delazify always uses it. Instead I'd rather we just try to shrink FunctionKey to u32 (Bug 1687400)

In the future I'd like to remove Xdr.{cpp,h} entirely and stop doing these byte-by-byte operations.

checked yahoo-mail:

script,gcThing,scope <= 0xff, regExp,bigInt,objLit == 0   : 5312
script,gcThing,scope,regExp,bigInt,objLit <= 0xff         : 2429
script,gcThing,scope <= 0xffff, regExp,bigInt,objLit == 0 : 6
script,gcThing,scope,regExp,bigInt,objLit <= 0xffff       : 27
other                                                     : 0

also on google-mail:

script,gcThing,scope <= 0xff, regExp,bigInt,objLit == 0   : 9584
script,gcThing,scope,regExp,bigInt,objLit <= 0xff         : 598
script,gcThing,scope <= 0xffff, regExp,bigInt,objLit == 0 : 7
script,gcThing,scope,regExp,bigInt,objLit <= 0xffff       : 14
other                                                     : 0

and on twitch:

script,gcThing,scope <= 0xff, regExp,bigInt,objLit == 0   : 6935
script,gcThing,scope,regExp,bigInt,objLit <= 0xff         : 2523
script,gcThing,scope <= 0xffff, regExp,bigInt,objLit == 0 : 5
script,gcThing,scope,regExp,bigInt,objLit <= 0xffff       : 21
other                                                     : 0

So, I think having the following options should be sufficient:

  1. script,gcThing,scope fits 1 byte, other are 0
  2. all fits 1 byte
  3. all fits 2 bytes
  4. other (all fits 4 bytes)

Based on your numbers, we might be fine to combine case 3/4. They are less than 1% of stencils.

Attachment #9197663 - Attachment is obsolete: true
Attachment #9197662 - Attachment description: Bug 1687093 - Part 1: Do not encode the size of spans in BaseCompilationStencil if empty. r?tcampbell! → Bug 1687093 - Compress the size of spans in BaseCompilationStencil. r?tcampbell!
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/46a0b32e53b1 Compress the size of spans in BaseCompilationStencil. r=tcampbell
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 86 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: