If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Make date-format-xparb String.leftPad faster

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
RESOLVED WORKSFORME
7 years ago
6 years ago

People

(Reporter: dmandelin, Unassigned)

Tracking

(Depends on: 1 bug)

Trunk
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

7 years ago
The majority of our slowdown vs. JSC on date-format-xparb is in its function String.leftPad:

    String.leftPad = function (val, size, ch) {
        var result = new String(val);
        if (ch == null) {
            ch = " ";
        }
        while (result.length < size) {
            result = ch + result;
        }
        return result;
    }

I know JSC has optimizations for prepending to strings. A general prepend optimization may not be necessary. Other things that might work:

- have ropes speed this up somehow
- some kind of single-character prepend optimization
- some kind of optimization specific to the pattern in this padding function

JM wanted SS win: 15 ms

Comment 1

7 years ago
Looks like most of those milliseconds are spent in the call to new String(). Change

var result = new String(val);

to

var result = "" + val;

and you'll see it speed up by about 10ms.

It looks like the Add stub is wasting a lot of time calling js_DefaultValue, so that could explain the rest of the slowdown.
(Reporter)

Updated

7 years ago
Depends on: 578452
(Reporter)

Updated

7 years ago
Depends on: 578456
Blocks: 601816
We've caught V8 and JSC on xparb, so I think we're done.
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.