Live data from Hacker News

Show HN: Fast.js – faster reimplementations of native JavaScript functions

github.com

151–160 of 168 posts

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#151
post #80

Earlier quoted context omitted.

I think it's a bit unfair to label using a known fast library over a known slow library as "premature optimization". I would much rather start a project or feature with the coding standard of, "use the fast ones", rather than have to go back through all the code, profile it, and replace only the ones hurting performance.

> start a project or feature with the coding standard of, "use the fast ones" Ironically, that involves certain habit changes that completely obviate the library: 1) avoid map. Just create an array and write a for loop directly at the callsite, putting the code in a block rather than as a separate function 2) avoid indexOf. For single-character indexOf, it's much faster and much more efficient to match the character…

Umm okay, but that rather misses the point.

The point of this library is that it provides the same behavior (for 99.99% of cases) and the same abstraction (so same readability / maintainability) as the functions it replaces, but with significantly better performance (for wildly varying degrees of "significantly" depending on usage).

I don't think the idea is that you profile your code and then micro-optimize it using this library. If you're doing that (which you should, for varying definition of "should"), then yes you will want to consider sacrificing the abstraction / brevity for performance.

However, this library seems like a handy way to maintain the abstraction, while gaining performance essentially for free without sacrificing anything worth mentioning. Then you profile (if you were going to / had time to / cared enough to) and optimize from a better starting point. Don't see anything wrong with that.

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#154
post #80

Earlier quoted context omitted.

> start a project or feature with the coding standard of, "use the fast ones" Ironically, that involves certain habit changes that completely obviate the library: 1) avoid map. Just create an array and write a for loop directly at the callsite, putting the code in a block rather than as a separate function 2) avoid indexOf. For single-character indexOf, it's much faster and much more efficient to match the character…

Umm okay, but that rather misses the point. The point of this library is that it provides the same behavior (for 99.99% of cases) and the same abstraction (so same readability / maintainability) as the functions it replaces, but with significantly better performance (for wildly varying degrees of "significantly" depending on usage). I don't think the idea is that you profile your code and then micro-optimize it using…

[deleted]

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#155
post #80

Earlier quoted context omitted.

I think it's a bit unfair to label using a known fast library over a known slow library as "premature optimization". I would much rather start a project or feature with the coding standard of, "use the fast ones", rather than have to go back through all the code, profile it, and replace only the ones hurting performance.

> start a project or feature with the coding standard of, "use the fast ones" Ironically, that involves certain habit changes that completely obviate the library: 1) avoid map. Just create an array and write a for loop directly at the callsite, putting the code in a block rather than as a separate function 2) avoid indexOf. For single-character indexOf, it's much faster and much more efficient to match the character…

So basically treat most of your JavaScript logic/functions as if you were writing C?

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#156
post #90

Earlier quoted context omitted.

> Premature optimization is the root of all evil -- Knuth HN should have a bot that posts the full quote whenever this line is cited since it's so often abused. "There is no doubt that the grail of efficiency leads to abuse. Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative im…

> Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs Isn't that essentially what I described? "Before seeking a third party library, be sure to check if the function is called many times or is taking a long time." On the issue of this particular library: The problem is that you can do much much better by avoiding map, forEach and friends. The…

Swap to use a slightly faster function someone else already wrote, or rewrite your code. Seems like the latter is more guilty of premature optimisation if this library is fast enough for the particular use.

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#157

Earlier quoted context omitted.

But IE didn't support SVG either until recently? If I read right, it was supported since the same version as HTML5 canvas (IE 9), http://caniuse.com/#cats=SVG http://caniuse.com/canvas

Tools like http://raphaeljs.com/ allow you to support older versions of IE.

But likewise you can use excanvas.js to let your canvas code run on IE (emulates it using VML)

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#158
post #126

Today i was refactoring some js code that rendered a graph to svg. It was taking several seconds in some cases, and the developer had done a bunch of micro-optimizations, inlining functions, building caches to avoid nested loops, and so on. I ran a profile. The code ran for 2.5 seconds, 4 ms of which in the micro-optimized js code, the rest updating the dom, five times all over again. Needless to say that i threw out…

I have done some optimizations using the Safari Debugger alongside with Chrome's, because I needed to access an iPad.

Safari counts and profiles ALL function invocation, so if you go looking for hotspots with it's profiler, you always get the parts where many functions are called. I consider this harmful.

I stumbled over this. Maybe other developers did too.

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#159
post #73

Here's a jsperf of fast.js / lodash / native: http://jsperf.com/fast-vs-lodash

Native bind in Safari is much faster.

bind - fast 2,565,227 ±2.19%

bind - lodash 4,923,373 ±1.51%

bind - native 9,022,396 ±2.12%

on iPad this difference is even larger.

Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions

#160

Reminds me of this comment by Petka Antonov on native V8 Promises being way slower than Bluebird[1]: >I'd expect native browser methods to be an order of magnitude faster. Built-ins need to adhere to ridiculous semantic complexity which only gets worse as more features get added into the language. The spec is ruthless in that it doesn't leave any case as "undefined behavior" - what happens when you use splice on an a…

> Additionally, since you pretty much never need the return value of splice, you can just not return anything instead of allocating a wasted array every time That kind of optimization seems easily done with a builtin as well: have an option to return the array, and only do so if the JavaScript engine indicates that the calling code actually uses the return value.

That seems like something well suited to compile-to-js languages like Coffeescript. It could substitute cases as you mentioned with fast.js equivalent functions.
Post reply on HN