millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

performance: it is too slow to be used on big files #3

Closed millermedeiros closed 11 years ago

millermedeiros commented 11 years ago

did a "quick" (not as quick as I expected) test using jQuery 1.8.3 and it takes forever to process the file.

half of the reason is because rocambole is too slow (see millermedeiros/rocambole#4), the other half of the time is spend on sanitizeWhiteSpaces and executing the hooks for each node.

I added a few console.time and console.timeEnd calls, here is the output:

opts     : 2ms
indent   : 2ms
trail    : 1ms
empty    : 0ms
parse    : 184354ms
sanitize : 61622ms
moonwalk : 119392ms
toString : 20ms
TOTAL    : 365393ms (aka. forever)

Still need to profile it better (only did the console.time so far) but I know I'm doing a lot of unnecessary work (lots of function calls and removing/inserting unnecessary tokens).

I hope to bring the total time below 5 seconds (ideally under 3s), lets see how it goes.

Make it right before you make it faster.

PS: I will probably "finish" the support for all statements before working on the performance.

millermedeiros commented 11 years ago

I just released rocambole v0.2.3 which improves performance A LOT! now it is able to format jQuery in under 4s (could still be improved).

opts     : 2ms
indent   : 2ms
trail    : 1ms
empty    : 0ms
parse    : 3154ms
sanitize : 9ms
moonwalk : 603ms
toString : 21ms
TOTAL    : 3796ms

~95x faster! :+1:

will close this bug for now and maybe improve rocambole even more in the future.