-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplified event handlers - Option 1. #235
Conversation
Testing with my jsfiddle locally shows exactly the desired behavior and sequence, now identical whether a "normal" or "parameterized handler.
|
And the obvious comparison, against 3.4.12 parameterized handlers:
Measured Time: 6044 |
Finally, with DOMVM and my other pull-request, which adds a listen to each VM's element. It's worth noting here that memory consumption does not appear to change whether 1 or 1,000,000 listeners are used, which is consistent with my expectations that the
Measured Time: 6793 |
Personally, I think the relatively tiny added time (it is after all about 1us per event handler on my HEDT) is probably well worth the total consistency with the native event system. But it should definitely be measured on other systems as well. And en toto performance should be gauged (there may well be other hidden improvements offsetting the added time here). The handler attach time will be dwarved into insignificance by the construction of a real-life DOM where the handler will represent a tiny part of the overall work -- this synthetic test magnifies the cost of adding an event handler (by intentional design). |
hey @lawrence-dol i've pushed some changes on top of your work in https://github.com/domvm/domvm/tree/onx-events
please maintain the existing style of the rest of the codebase (commas, alignment, spacing, prefer overall this looks pretty promising. my biggest concern, as i've stated before, is that non-parametrized handlers should be invoked as they would in raw dom. we can still bind our proxy handler, but it should invoke the original handlers with the raw event and properly-bound this. let's leave all the special magic in the domain of parametrized handlers. i think once this is done, it will fix the remaining failing tests that now fail due to wrong parameter counts, and additional invocation of global and vm onevent handlers. let me know how this works for you. here's what i'm using for local testing: <!doctype html>
<html>
<head>
<title>Perf test</title>
<script src="./dist/nano/domvm.nano.iife.js"></script>
</head>
<body>
<script>
let {
createView: cv,
defineView: vw,
defineElement: el,
} = domvm;
let App = (vm, data) => {
let showAll = true;
const toggle = e => {
// showAll = !showAll;
vm.redraw();
};
return (vm, data) => (
el("div", [
el("button", {onclick: toggle}, "Toggle"),
showAll ? vw(Table, data) : null,
])
);
};
let Table = (vm, data) => {
let onclick = (v, i) => {
console.log(i, v);
};
return (vm, data) => (
el("table", data.map((v, i) =>
el("tr", [
el("td", {onclick: [onclick, v, i]}, v)
])
))
);
};
const data = Array.from({length: 3500}, () => Math.floor(Math.random() * 1000));
cv(App, data).mount(document.body);
</script>
</body>
</html> |
P.S. we may need to switch back to using add/removeEventListener, i remember back in the day that there were some events that had no equivalent assignable we will also have to go through all the demos in the playground and make sure they still work as before, especially ones that rely on event bindings: https://domvm.github.io/domvm/demos/ |
Completely agree, and tried to do that, at least with respect to When I was looking into tests, I found I had unintentionally broken compatibility with the
|
That rings a bell with me too, now that you mention it. As simple as:
no? |
you'd need to do let me know what you find, but unless we can pinpoint which events have no |
So I just found out. I pushed what I think are the final three changes on my branch. (Sorry if I've done anything incorrectly, here -- this is my first time collaborating like this on github).
I can't detect any material difference between In the end, I am ambivalent and defer to your judgement on the matter. Feel free to accept or reverse that commit. |
I'm happy to help with this to the extent I can (I don't necessary know what to expect, and my not notice if anything works incorrectly). Just point me in the right direction. But for today, I am wrecked, so I'm packing it in until tomorrow. |
i've added the extra changes for raw events and merged this work into i've also updated the dependencies and build script so you'll need to re-run any followup work should be done in a new PR. but feel free to continue discussing/planning in this thread. the only real behavioral change affected whose vnode is supplied as the |
Looks great. Thanks!
I'll sleep on it, and look over some event handling code tomorrow to get a more concrete understanding instead of merely theorizing -- you might well be right. Will try to have a firm opinion by EOB tomorrow. |
After reviewing a wide range of existing code, it seems I am about equally often interested in the Therefore, my conclusion is that it's a wash in terms of usefulness of one over the other, and backward compatibility dictates it should remain as it was, the target vnode. Could you please proceed with a new release as soon as you are satisfied it's ready? |
ok, thanks. i'll let it simmer over the weekend and see how i feel about it in a couple days. but like you said, backwards compat will probably be the tie-breaker. in the mean time, please test the hell out of the new implementation and let me know how it functions and performs relative to your expectations; you're likely the only domvm user with such intricate event handling requirements. |
I've integrated the new build into several apps, with a mix of handlers, and so far have observed no adverse effects. I do have to be a little bit cautious, as all my apps are in production and I don't want to prematurely deploy code. But so far, so good. |
@leeoniya : Could you release 3.4.13 now? Also, 3.4.12 was never released here on Git Hub. |
I love seeing you guys in my inbox! Good work the pair of you 🚀 |
sorry a bit busy this week with work. will take a look over weekend. |
@leeoniya : Reminding you about 3.4.13. |
@leeoniya : Reminding you again about releasing the next version. I need to put this production in the next few days and would like to do so with an "official" build. I'm open to doing it myself, if you have instructions and want to enable me to do so. |
sorry! will tag/push a release tomorrow. |
3.4.13 is published |
This change simplifies event handlers to be immediately attached using
onxxx
attributes, with a fixed DOMVM intermediary which invokes the VM and globalonevent
handlers.The memory and performance comparisons follow (with 1,000,000 elements).
Vanilla JS
No handlers:
Measured Time: 625 ms
With
onclick
handlers:Measured Time: 1816
DOMVM
No event handlers:
Measured Time: 6305
With
onclick
handlers:Measured Time: 7344