-
Notifications
You must be signed in to change notification settings - Fork 110
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
New registry #39
New registry #39
Conversation
I think simple benchmarks for all the public api methods would be a good sanity check. Make sure that attaching/removing events doesn't take like 100x as long if you've attached 1000 events. Things like that. |
also, it's fairly comment-free at the moment, I'm intending to put notes in about some of the more non-obvious things to aid maintainability. |
sounds good |
Conflicts: src/bean.js
A bunch of minor little code cleanups and also a heap of optimisations to find extra speed; such as replacing for-in loops with proper indexed for loops on arrays. Also changed the way one() is called to make add() much faster by removing the intermediary call and _add(). one() now does a custom `this`.
created a benchmark test thing tonight here 6bd6861 I'm going to run it through a few of the major browsers tomorrow - some interesting things already popping up! I'll try to run your branch through tomorrow as well and do some comparisons. |
Custom events get the full fixEvent() treatment since #27 but it turns out that there's a *lot* of work in there for some browsers. So, now we just do a basic augmentation of non-native custom events rather than the full deal.
Added nwevents as a submodule as a reference, along with jQuery for benchmarking (even though they are not directly comparable to Bean). Added fixes for noConflict() to bean.js so we can compare it as original to src/bean.js as the new code.
Well seeing that you've progressed in this area I thought I'd better check-in and push all my local changes because I've also progressed and we're probably overlapping a bit. My benchmarks.html takes a different approach to yours, a bit simpler but able to compare current-bean to my new-bean and also throw in NWEvents and jQuery as well to see what it's up against (even though they all take different approaches so it's not quite apples-to-apples, but it does point out the weak points). My original version didn't perform particularly well so I went searching for optimisations and found plenty, both in my code and across the rest of Bean. I've also done some other minor clean-ups which largely boil down to questions of style, but I couldn't help it. Benchmarks across browsers are a hugely mixed-bag, although I guess it should be no surprise since we're dealing so much with natives. Custom events on DOM elements is greatly improved on all browsers but that's largely to do with commit b644594 and some other work on Regarding the rest, the biggest wins are visible in Chrome and Safari where my latest code runs roughly 20% faster on average in the different tests. The biggest losers are Internet Explorer 9 and Opera but the results are harder to summarise on those. The one that stands out is the plain I was planning on adding one more test to the benchmark suite, one where multiple event types are used, multiple custom and multiple native, to better reflect normal usage. Because I'm storing entries in the registry by event name/type I was suspecting I'd see a slight boost in this situation because the other tests use a single event name. But now I have this all checked in I might check yours out and have a look. |
@@ -12,7 +12,9 @@ | |||
else if (typeof define == 'function' && typeof define.amd == 'object') define(definition); | |||
else this[name] = definition(); | |||
}('bean', function () { | |||
var win = window, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was in the noConflict PR I put in, I needed noConflict()
to work so I could test bean.js (old) against src/bean.js (new).
After having put that comment in there about the benchmark numbers I realised I went and put back in some more realistic numbers that I had before trying to make old IE happy, something like:
So there's 100 listeners per iteration and more iterations are run. |
Awesome glad to see you were thinking this through! I think i'd rather stick to using benchmark.js - @jdalton has been working alot on this stuff, so I imagine there's some trickiness in the lib worth leveraging. Shouldn't be too hard to add other libs to the benchmark.html page I've already setup. |
I've updated this branch as |
@fat lemmie know if ya have any usage tips/tweaks or issues w/ benchmark.js |
@jdalton I will definitely - so far really great stuff :) |
Updated |
new bean, old bean, NW & jQuery interesting, but hard to run on older browsers and slightly sus
Work-in-progress but I've updated benchmark.js-based benchmarks to be multi-library and compare old/new. I'm also having a ton of trouble getting anything meaningful out of older browsers and even IE9 is having difficulty running these; @jdalton if you're looking for something to geek out on then you could have a poke around in there for us. Certainly one thing that you might want to look at is I'm getting errors in FF3.6 (haven't tried anything between that and Aurora just yet), it's complaining about |
@rvagg FF 3.6 is erroring on yur setup/teardown compiling because it doesn't support For older IE's you may need to apply a patch to avoid long script warnings: For IE also add the nano applet to your test page. That will allow the tests to run shorter. Also you should avoid iterating inside a test. These tests will be repeated a lot already without the need for |
Thanks for all the good info. |
@rvagg The test setup/teardown is explained in the documentation with examples of how things compile. (I'll be sure to add a note about how we handle compiling and the strengths and weaknesses of different ways to compile) Also be careful of tests which append or remove elements to the document because this could happen hundreds of thousands of times in a test. In yur setup and teardown properties you can reference |
OK, I'm pretty happy with where this is for now. IMO speed is decent enough considering the change, but that's a matter of opinion. I haven't had time to run the benchmarks as they are now on older browsers but there are 3 more at the end now that do an add/fire/remove sequence. The A couple of additional thoughts I've had on performance:
Feel free to comment in the diff and I'll try and address any concerns. Oh, and if you're going to accept this PR, since it's so major, we could switch coding style to semi-colon-free and comma-first if you wanted; it looks like that's your current preferred style. |
I'm going to try to run through this next week... i'm currently swamped at work, but I am very much looking forward to digging into this. Keeping this project really lean is important to me as it does a great job for people developing 3rd party js. |
…alized which properties are actually used.
i'd love to finally get this in @fat. plus the non-standard layerXY is getting super annoying to look at in the chrome console |
But the delay is understandable. If I had an OS project with 12,549 watchers and 2,161 forks, I think I know where I'd be spending my free time! |
slightly stricter jshint, moved code blocks around so that declarations always appear before usage.
…stry Conflicts: src/bean.js
Since I've been reminded of this I decided to go ahead and finish up the other things I wanted to do with this branch. I've changed the coding style to comma-first & sans-semicolons which I'm guessing you'll be cool with. I've put in a few extra JSHint options and reorganised the code slightly so that things are defined before they are used in the source, I've reformatted and renamed a few things just for readability sake without sacrificing minified size. I'm certainly finding the current version really easy to look at. The diff isn't very helpful to look at now unfortunately. If I've gone too far here let me know, I didn't want to make it harder to review the code but I thought I may as well go the whole hog as long as I'm making major changes. I also merged @paulredmond's changes in #47 which basically makes Current Bean is 2558 bytes, minified and gzipped, my latest with registry is 3089. I've published a new bean-rvagg-wip to NPM with these changes if anyone wants to have a go. I'm currently running it against a Bean (and Bootstrap) dependent product in-house with no issues. |
@rvagg that's good news. i'd love to use your temporary published package |
Awesome! Great job @rvagg |
@rvagg i'm thinking more I should just give you commit access on this project - is that cool? As you pointed out, i'm definitely swamped - and it's not that this isn't a super important project. We're currently using bean for tweet embeds (which are everywhere now), plus it's used by disqus, storify, and nearly every other major embedded project. If your interested let me know, and then you can merge as you see fit - how does that sound? |
hooray |
Sure, commit access would be great! |
alright - you should have commit access - that doesn't mean go crazy though! Remember, if you break bean, you break the internet. :) |
awesome, I'll have to think up some clever subtle ways to break the internet then that don't make it look like my fault. |
FYI I'm not going to merge this straight away, I think we need some tests for custom events (mouseenter/mouseleave). It looks like they might not be working quite right with the new code, in 2 areas: So, anyone who wants to be using the new stuff (to test it out in the real world!) should still try bean-rvagg-wip from NPM, or grab the source from https://github.com/rvagg/bean/blob/newregistry/src/bean.js if you're not using Ender. |
a bunch of fixes for |
Following on from #19 (comment)
Critique away.
I'll try and come up with some benchmarks when I have a bit more free time, I'm happy to take suggestions on exactly what you'd like to see benchmarked tho.
Cheers.