Open Bug 1330183 Opened 7 years ago Updated 2 years ago

Adjust baseline warmup thresholds for event handlers

Categories

(Core :: JavaScript Engine: JIT, defect, P3)

defect

Tracking

()

People

(Reporter: sfink, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

This is an idea from Anthony Jones or Chris Pearce. I think.

As I understand it, the baseline warmup threshold is to avoid doing a baseline compile for code that is going to run too few times for the compilation to be worth it. But for an event handler, at least one that ends up getting called, the tradeoffs are different -- ideally, you really want it to fully parsed and precompiled, to minimize the startup latency (which is much more  likely to be observed for an event handler, unlike an arbitrary script where there are decent odds that it will never even run.)

Although they are not all the same, this would apply to things passed to addEventListener, rAF, and timeout handlers.

I don't know if this makes sense if all we can see is the toplevel script and not all the scripts called by it. Assuming this is workable in the first place, would it be possible to propagate the eager compilation request down to callees, at least a level or two?
Are you seeing a lot of time spent in the interpreter or baseline compiler for event handlers? The baseline compiler itself is fast, so I don't think the time there matters much, and precompiling could backfire for event handlers like onload that run only once. We could consider tweaking our Baseline thresholds though.

(In reply to Steve Fink [:sfink] [:s:] from comment #0)
> Assuming this is workable in the first
> place, would it be possible to propagate the eager compilation request down
> to callees, at least a level or two?

We don't really know the callees in Baseline. Heuristics could be used but I really don't want to go there...
(In reply to Jan de Mooij [:jandem] from comment #1)
> Are you seeing a lot of time spent in the interpreter or baseline compiler
> for event handlers?

This is based on an idea that came up during discussion, not actual profiles. It may not serve an actual need, but I wanted to get it recorded. If we can conclude that it's not going to help or is unworkable, it'd be nice to have the reason recorded in a bug. Even if it does sound worth doing, its priority should be based on the effort and expected reward; no need to jump on this unless we come up with a reason to believe it might big a significant win and it's not too hard to do.

But to answer the original question, this would fix hypothetical time spent in the interpreter.

> The baseline compiler itself is fast, so I don't think
> the time there matters much, and precompiling could backfire for event
> handlers like onload that run only once.

Yeah. We could use heuristics to try to avoid things like that. I don't know how high the cost is (in memory, I guess?) of compiling run-once scripts.

> We could consider tweaking our Baseline thresholds though.

That would indeed be safer, though I assume that wouldn't speed up the first invocation any if at all. And the first, or at least first few, invocations are what this bug is targeted at. The ideal would be if the first run of an event handler went straight to running baseline (so it would need to be preparsed and precompiled.)

> (In reply to Steve Fink [:sfink] [:s:] from comment #0)
> > Assuming this is workable in the first
> > place, would it be possible to propagate the eager compilation request down
> > to callees, at least a level or two?
> 
> We don't really know the callees in Baseline. Heuristics could be used but I
> really don't want to go there...

I suspect that makes this idea less interesting. If an event handler is slow enough that precompiling it would help, then I don't know how often it would be the toplevel script that is taking lots of time. I would expect that usually, most of the time would be in called functions. (And by toplevel script, I mean the JSScript invoked by the event handler. It's not necessarily the toplevel script in a file; I think event handlers are passed to JS_CompileScript as soon as they are read from the HTML?)
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.