Closed Bug 1591481 Opened 2 years ago Closed 2 years ago

Do less copying when external strings are passed back into the DOM

Categories

(Core :: DOM: Bindings (WebIDL), task, P1)

task

Tracking

()

RESOLVED FIXED
mozilla72
Tracking Status
firefox72 --- fixed

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

(Regressed 1 open bug)

Details

Attachments

(3 files)

Consider the attached testcase, which passes a long string through Web IDL to a callee that does almost nothing with it. The string originally came out of Web IDL bindings, and hence is an external stringbuffer-backed string. With our current setup, that causes a copy on the callee side, and copying a long string takes a while. The testcase outputs the average time per call, in ns.

In an unmodified build I see times on the order of 600 us (600,000 ns) per call. With my changes I see times on the order of 100ns per call, at the iteration count in the testcase; it gets even faster (~30-40ns) with more iterations and better JIT-compilation.

Summary: Do less copying when external strings are passed back into the DOMCon → Do less copying when external strings are passed back into the DOM
Attached file Testcase

The codesize impact is approximately 0 (actually positive by a a few KB),
because AssignJSString is not inlined.

If we were to force-inline AssignJSString, that would actually save ~115KB
based on bloaty measurements for linux64 shippable opt builds (so with LTO),
because then ConvertJSValueToString stops being inlined in bindings.
Given that ConvertJSValueToString pretty much always calls AssignJSString, so
there is no slowdown from changing which of them is inlined, this is really
tempting to do, but I don't want to mess with compiler inlining heuristics...
Inlining both AssignJSString and ConvertJSValueToString increases codesize by
~2MB, so that's definitely not desirable.

Priority: -- → P1

It already is in the nsAString case; we just ignore the failure if it happens!

Attachment #9104259 - Attachment description: Bug 1591481. Don't force copying when external strings are passed to Web IDL bindings. r=mccr8 → Bug 1591481 part 2. Don't force copying when external strings are passed to Web IDL bindings. r=mccr8
Blocks: 1591514
Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/dd64db27cdb8
part 1.  Make NormalizeUSVString fallible.  r=mccr8
https://hg.mozilla.org/integration/autoland/rev/72dac552b387
part 2.  Don't force copying when external strings are passed to Web IDL bindings.  r=mccr8
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72
Regressions: 1593228
Regressions: 1593296
Duplicate of this bug: 1330671
You need to log in before you can comment on or make changes to this bug.