Servo: Use proc macro to only check against applicable event handler content attributes.

Created on 14 Feb 2020  ·  4Comments  ·  Source: servo/servo

See https://github.com/servo/servo/pull/25274 for the first attempt

Currently we compile any content attribute that starts with "on" as an event handler.

What we should do is still check for "on", but then only compile it as a handler if it belongs to the list of event handlers allowed on the element (see global_event_handlers and window_event_handlers)

A macro based approach was tried, but it slowed things down (see https://github.com/servo/servo/pull/25274/ ). We should instead use a custom proc macro to generate the match statement, or perhaps a phf_map

cc @jdm

A-contendom I-wrong

Most helpful comment

I looked into it (it took me a little while to get the old branch built). ELEMENT_EVENT_HANDLERS contained atoms like "blur" and "click" without the "on". You had elements looking up the full attribute name including the "on", and thus never found a match. I didn't observe any performance problem distinguishable from the usual slight sluggishness of Servo on my VM.

All 4 comments

Are you sure 25274 was slow? I haven't given it a close inspection, but as I said there, a lot of these event tests will report TIMEOUT if the callback with step_func_done() in it never fires.

I think the lazy_static caused an initial expensive setup, but also I'd be surprised if there was a behavior change that caused those timeouts. Feel free to investigate if you'd like.

I looked into it (it took me a little while to get the old branch built). ELEMENT_EVENT_HANDLERS contained atoms like "blur" and "click" without the "on". You had elements looking up the full attribute name including the "on", and thus never found a match. I didn't observe any performance problem distinguishable from the usual slight sluggishness of Servo on my VM.

Something else went wrong elsewhere in my attempts to use #25274 (and I've closed #25249), but the only code changes needed to get it _mostly_ working were to have the make_array macro use concat!("on", ...) and to put "on" in the elements of in the handwritten array of ["cut", "copy", "paste"]. I still hit a problem where an "onx" content attribute of a document body seemed to be firing for a dispatched "x" event, but it wasn't the macro part that was at fault.

Was this page helpful?
0 / 5 - 0 ratings