-
Notifications
You must be signed in to change notification settings - Fork 21
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
Compile Evals #2
Comments
Some programmers use that as a unofficial standard to help flag variables as DOM variables. |
I had no time to look at your code yet (bussy week at work). But what you write in your post sounds great - and a 99% rewrite of the script. I hope there is something left of my idea besides the name vlex :-) just to reply to some of the things you mention: you are right, there is no need for elParent - web components would be a solution here. But they are not very well supported in general and its even worse within a svg. I have to confess i haven't thought about requestanimationframe. I have used it quite often before and i am familiar with it but i only thought about underscores throttle function that i often use for onresize functions. I will have a look at RAF. data attributes I hope your internet connection is down more often... |
Its far from a 99% rewrite ;)...when you look at the code you'll see, I always try to keep it same. elParent is just that in your code you have el.parent a few times and since it doesnt change I cached it, because of this.... I use to use Cowboys throttle, but requestframe just seems to make sense. I made a little mistake in the data attribute stuff, I fixed it.... ."I hope your internet connection is down more often..." @tomByrer |
@tomByrer @indus Im sorry if Im getting a little carried away playing with your code. Im not trying to step on your toes, take over, or any of the other things Ive been accused of over the years. Im just passing time, having fun. I dont care if you dont use any of this or all of it (I dont even know if I will yet ;) ). I love your idea and your code and so keep playing with it. I would have never made this like this and love yours. And sooner or later Ill disappear and you'll never have to put up with me dribbling ever again ;) Micro Optimizations |
http://jsbin.com/ditogatu/8/edit |
Likely much faster also; 2-3 asm opcdes vs a full function.
Could always inject the logic. In your jsBin, is that JavaScript pane your version of the VLEX library? There are a number of linting errors... |
Yeah, thats its. |
Thanks for fixing the linting errors! |
But it would be soooooo much slower than this. What Im thinking about now is could there be a way to "compile" a VLEX? |
So true. Hard to balance speed, security, coding time, & idiot-proofing.
That's an interesting concept! Infact, that is how Handlebars.js "precompiles" the |
Yeah, Ill try out the compile idea either today or tomorrow, unless I try the element options idea first ;) Small Optimization EDITEDIT: |
http://jsbin.com/ditogatu/15/edit Here's a version with rudimentary compile. Now to try and find out why this sample has stopped rendering right since the last update to Chrome...still works fine in FF. |
http://jsbin.com/daboxesa/6/edit Works fine in Chrome 34.0.1847.131, but it does run slower than my Firefox 24 for some reason. |
Yeah my earlier Chrome was fine AND ran at the seemingly same speed as FF...to the best of my crap memory anywayz. So thats a delta timer to add and the v-order stuff and then I might try actually using it ;).....oh and then I might look at having more than one on the page at once. Once again I don't need that, but its been bugging me.....although to be honest if there was one thing I didn't do it would be that. hehe...I still haven't even checked to see if I could do what I want with svg, not properly anywayz...but Im pretty sure with this things help I could. I want to make an online chrome theme creator (a very specific type a freind came up with, CTTM) and was hoping to be able to do the preview with svg so it could resize nicely....its going to be a pain, but I think it could be done. EDIT: |
Seems to be common; helps all animation sync to 1 heartbeat. |
V1
http://jsbin.com/duvayova/1/edit
V2
http://jsbin.com/ditogatu/5/edit
I had no net for a couple of days (ooooh the humanity!) so played with your code for something to do.
Originally I was only interested in changing eval to new Function to speed things up, but ended up doing a little more.
I dont even know if I'm going to use this, but was thinking of maybe doing some svg and will want something like this. I like your version coz its simple and works....the best sort of code.
Anywayz, was just passing time and trying out some ideas, cant say at all if even any of them are actually good ideas ;)
Do what ever you want with this.
Things I changed....
Compile evals
The thing I was originally interested in...then I got carried away ;)
Instead of using evals as they where used, I tried using new Function instead to get an increase in speed, please check.....
http://jsperf.com/eval-vs-new-function-constructor/6
I then changed that to using an eval to compile a function in an anonymous function, for the below...
Remove the need for $ before variables
This just makes things cleaner to me.
I ended up making two versions to try out two ideas.
V1 - Uses new Function and passes the global variables to the function through its parameters.
V2 - Uses the fact that VLEX is defined within an anonymous function to pull it off. All variables to do with VLEX are attached to VLEX to avoid collisions and only those I wish are exposed to the scripts.
Personally I prefer V2 but I wonder about speed....variable lookup Vs parameter passing, I guess
Removed $ in the code
Tried to get it so that $ and _ aren't used anywhere to avoid any future probs with jQuery and Underscore...but then used it for the default for store as I couldn't think of anything else and you "probably" aren't going to need jQuery in a VLEX script.
Use requestFrame
The "idea" here was to try and make it more efficient by only updating when truly necessary and only once....seems to have made a difference but wouldn't know how to rate the difference....I just went by how it looks when I move it on the screen and the new way is alot smoother.
In the past when Ive done things with mousemove or resize they fire so often it was a problem. And I'm pretty sure I read something to do with the idea if you only do these sort of things on the requestframe then the browser only redraws once.
Store....for the lack of a better name
This is something to bridge between the VLEX and the outside world, which you already had.
Right now you can change the variable name to be used within the scripts for this through options. But Id think about removing that ability. It makes for inconsistent scripts (between users) and I wonder if theres any speed benefit to calling a function with no parameters? You could just attach variables/woteva to VLEX, but thats likely to cause a collision.
$$
Due to the way it now works you can use "this" in your scripts as the function is attached to the node.
elParent
Assumes the parent of el wont change.
data attributes
Where not meant to be making up attributes how we like, apparently they should start with "data-". Personally I hate this (its so freakn ugly), but some html validators spit on it and so some people may want to be able to use "data-vlex".
Usual Disclaimer
Im not the best coder and all that, not the worst either tho ;)
Im prone to lots of dumb mistakes and have the worst memory of any coder.
Take all my advice/suggestions with a pinch of salt and double check everything.
The text was updated successfully, but these errors were encountered: