Open Bug 1420440 Opened 7 years ago Updated 2 years ago

Optimize the Function constructor

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

Performance Impact low
Tracking Status
firefox59 --- fix-optional

People

(Reporter: jandem, Unassigned)

References

(Blocks 4 open bugs)

Details

On the UglifyJS test in V8's Web Tooling benchmark we spend a *lot* of time under CreateDynamicFunction. I think we end up parsing the same string over and over again. For the micro-benchmark below I get: SM: 820 ms d8: 81 ms If I add |+ i| at the end of the string, I get: SM: 1043 ms d8: 2123 ms So we're actually faster at this but they seem to do some sort of caching. It probably makes sense to have a source-string -> JSScript* cache. Then when we have a hit, we only have to allocate a JSFunction and we're done. Probably worth checking what V8/JSC/Chakra are doing exactly. --- function f() { var t = new Date; for (var i = 0; i < 100000; i++) { fun = Function('switch(str){case "(":case "[":case "+":case "*":case "/":case "-":case ",":case ".":case "`":return true}return false;'); } print(new Date - t); } f();
FWIW, in Safari 11.0 I get 1665 ms. If I concatenate |i| to the string, I get 1242 ms... not sure why that's faster instead of slower. In any case, JSC doesn't cache this either.
V8 seems to call Compiler::GetFunctionFromString -> GetFunctionFromEval, where they use the eval cache. So yeah, maybe we could just reuse the eval cache...
Priority: -- → P3
Blocks: 1427995
Blocks: 1475013
Whiteboard: [qf:p3:f64]
Whiteboard: [qf:p3:f64] → [qf:p3:f67]
Whiteboard: [qf:p3:f67] → [qf:p3]
Depends on: 1561328
Blocks: 1561328
No longer depends on: 1561328
Performance Impact: --- → P3
Whiteboard: [qf:p3]
Severity: normal → S3
Blocks: 1811541
You need to log in before you can comment on or make changes to this bug.