JSpeed
UPDATE
I haven't had much time to work on the AST implementation of this project, so I went back to the original version, that solely used regular expressions. I've posted a pre-release in the downloads section. You can read how to implement it by heading over to the wiki;
News
- There are defects to be ironed out with this project, and those will begin to diminish as I get more time to work on this. If you encounter problems, please post issues, thanks!
- I uploaded a new version (0.2.0), which has the index as an interface for JSpeed. This way, you can avoid having to setup the PHP object all together.
- I haven't worked on this project lately, due to time constraints and other interests, but I plan to redirect my focus towards it.
- Thanks for your emails! I will look into applying some of the optimizations in a later release.
The JSpeed engine analyzes different portions of your JS code for fragments which can be optimized, and substitutes them with faster code.
Optimization Example:
for (i=0;i<1;i++) {
j = i + 1;
f = Math.floor(i);
f = Math.floor(21.4);
}
for (i = 0, j = 0; i < 1000000; i++, j++) {
if (i == 4) {
var tmp = i / 2;
a = Math.abs(i);
}
if ((i % 2) == 0) {
var tmp = i / 2;
tmp = Math.min(i,tmp);
i++;
}
}
var arr = new Array(1000000);
for (var i = 0; i < arr.length; i++) {}before: ~14 ms
for (var i=0;i<1;++i) {
j = i + 1;
f = i>>0;
f = 21.4>>0;
}
for (var i = 0, j = 0; i < 1000000; ++i, ++j) {
if (i == 4) {
var tmp = i >> 1;
a = i < 0 ? ~i++ : i;
}
if ((i & 1) == 0) {
var tmp = i >> 1;
tmp = i < tmp ? i : tmp;
i++;
}
}
var arr = new Array(1000000);
for (var i = 0, arr_len = arr.length; i < arr_len; ++i) {}after: ~7 ms
Features
- Helps make your code faster!
- Specify which part of your code (e.g. for-loops, function, global, etc.) you want JSpeed to target, and select which optimizations you want performed on it.
- Optimizations can be made via a regular expression, or through a callback function, in PHP.
- Minifies JavaScript code after it has been optimized
- Can take an array of scripts, and return each one separately, or concatenate them all into one (1) file.
Current Optimizations
- Division by 2,4,8
- Multiplication by 2,4,8
- Math.min optimization
- Math.floor optimization
- Math.abs optimization
- Even/odd check, i % 2 == 0
- Change for-loop conditional variables to local
- Post-increment to pre-increment
- Store array length in a variable in for-loops
- Code minification
- Join multiple scripts into one (1) optified (optimized/minifed) script.
Contact
If you have any inquiries or even have some optimization ideas to contribute, please send me an e-mail.
Thanks for looking!