Live data from Hacker News

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

github.com

131–140 of 168 posts

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

#131
post #130

Earlier quoted context omitted.

An ignorant question -- why do people prefer to render graphics to SVG/DOM, when that's such a noticeable performance bottleneck?

I can't speak for others, but if you write browser apps/websites for a generic audience you basically have no choice. The reason consist of two letters: IE

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

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

#132
post #117

Earlier quoted context omitted.

Note that 'in' for (key in object) is for getting keys, in Firefox, meanwhile 'of' for (value of iterator) is for getting values out of an Iterator.

Most of the array methods are explicitly defined in terms of indexing rather that iterators, so for(of) is incorrect. On the other hand indexing is still faster than iteration in the major implementations.

My comment were intended as a direct reply to phpnode's code, 'ignoring' the rest of the thread.

How do you mean when you state that for(of) is incorrect?

Perhaps this 'example' clears something up?

  « for (value in {a:1,b:2,c:3,d:4,e:5}) console.log(value)
  » undefined
    "a"
    "b"
    "c"
    "d"
    "e"
  « for (value of {a:1,b:2,c:3,d:4,e:5}) console.log(value)
  × TypeError: ({a:1, b:2, c:3, d:4, e:5})['@@iterator'] is not a function

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

#133
post #130

Earlier quoted context omitted.

I can't speak for others, but if you write browser apps/websites for a generic audience you basically have no choice. The reason consist of two letters: IE

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.

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

#134
post #130

Earlier quoted context omitted.

I can't speak for others, but if you write browser apps/websites for a generic audience you basically have no choice. The reason consist of two letters: IE

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

It is true, you can probably stop supporting IE8 depending on your audience.

[UPDATE: also I was reading SVG/DOM as an or]

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

#135
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…

[deleted]

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

#136
post #116

As a person who works on a JS engine I can say that a lot of the speed up in this library is the failure to handle holes correctly - it's surprisingly expensive to do a hole check, although there's still room in most engines to optimise it, those checks are fairly time consuming :-/

You can version manually or automatically in the optimizing compiler inner loops of those builtins depending on the denseness / representation of the array backing store. Something along this lines: http://gist.io/7050013. Trace compiler could actually give such versioning for free automatically.

So I always putting this into not-done-yet category for JS VM related work and it is a very interesting problem to tackle.

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

#138
I think this shows that standards bodies could implement less native language functionality and let community-made libraries/tools compete for those areas. ES6 goes so far as to implement a native module system, seriously calling into question any effort by the community at large to implement a competing system (e.g. browserify, requirejs).

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

#139

Earlier quoted context omitted.

Note that 'in' for (key in object) is for getting keys, in Firefox, meanwhile 'of' for (value of iterator) is for getting values out of an Iterator.

the only issue is i'd like to differentiate between iterating arrays and objects at the syntax level. Coffeescript uses `in` for arrays and `of` for objects, but I agree that becomes confusing. Open to other suggestions!

That's a though one. I know I can't think of any that aren't either verbose or nondescript.

But if Coffescript can walk away with its choice then I don't think you'll have anything to worry about.

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

#140

Here's another one for you, one of my favorites that used to be drastic: http://jsperf.com/pipetrunc blah | 0; // fast! Math.floor(blah); // slow(er)! (except on FF nightly) Caveat: Only works with numbers greater than -2147483649 and less than 2147483648.

Caveat: if you see numbers in the range of 1,500,000,000 that means your code was thrown away by the optimizing compiler.

Microbenchmarks like that require a lot of care to measure something correctly. Check out my talk from LXJS2013 for more details: slides http://mrale.ph/talks/lxjs2013/ and video https://www.youtube.com/watch?v=65-RbBwZQdU

Post reply on HN