Earlier quoted context omitted.
> 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.
Show HN: Fast.js – faster reimplementations of native JavaScript functions
161–168 of 168 posts
Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#162Earlier 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!
These are legal CoffeeScript examples:
for key, value of object
if key of object
for value in array
if value in array
for index, value of array
if index of array
The one that's missing is: for value in object
if value in objectRe: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#163Earlier quoted context omitted.
I think by all means use this for a shopping cart - it's namespaced by require (say under 'fast' as in the README) - you are, for all intents and purposes, calling just some library which just happens to reimplement JS builtins as its mode of operation. It may even be _easier_ to determine the behaviour of these functions than builtins, since determining how fast works just means reading its source whereas to determi…
I'm not sold that this will provide any user-measurable increase in performance. If you are sold by some personal app benchmark, there is a good chance you are writing too much client side JS. And what is to say of other dependencies like jQuery, Bootstrap, Knockout, Angular, etc that do NOT use fast.js under the hood? It seems that the only real "win" I get is a fast "map" command, which, IFAIK, has NEVER been the p…
Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#164Earlier quoted context omitted.
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!
I've been spending some time thinking about CoffeeScript's choice for `in` and `of` and I think I have the answer: they should be more regular. One (probably `of`) should be used for the keys/indexes and the other (probably `in`) should be used for contents. These are legal CoffeeScript examples: for key, value of object if key of object for value in array if value in array for index, value of array if index of array…
every element as key, value from arr {
console.log(key, value);
}
every property as key, value from obj {
console.log(key, value);
}Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#165Today 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…
Having written a major HTML5 game engine, I've ended up micro-optimizing JS code after small functions really did show up high in profiling measurements. One example: calculating a bounding box from a quad involved code along the lines of Math.min(a, b, c, d) followed by Math.max(a, b, c, d). Replacing that with a tree of ifs to determine both the minimum and maximum at once was faster and moved the bottleneck elsewh…
Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#166Earlier quoted context omitted.
You probably would have been better off with typed arrays and fragment shaders, if you were going for performance.
Aren't the arrays produced by a canvas object typed?
Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#167Earlier quoted context omitted.
I've been spending some time thinking about CoffeeScript's choice for `in` and `of` and I think I have the answer: they should be more regular. One (probably `of`) should be used for the keys/indexes and the other (probably `in`) should be used for contents. These are legal CoffeeScript examples: for key, value of object if key of object for value in array if value in array for index, value of array if index of array…
The issue with coffeescript is that it uses the opposite syntax to JS - `in` for arrays instead of objects. ES6 introduces the `of` keyword for real iterators so i don't really want to use that for either of them. It's tricky. There are other options but they're verbose every element as key, value from arr { console.log(key, value); } every property as key, value from obj { console.log(key, value); }
every [key, value] from arr {
console.log(key, value);
}
every {key, value} from obj {
console.log(key, value);
}
every [key] from arr {
console.log(key);
}
every {_, value} from obj {
console.log(value);
}
Looks a bit cramped to me but I get the impression that array comprehension is one of the major reasons that people use Coffeescript, so perhaps it's not too much trouble?There's also the issue with some fonts making it hard to differentiate between { and [ but it's an idea that might be worth to think about at least.
Re: Show HN: Fast.js – faster reimplementations of native JavaScript functions
#168Earlier quoted context omitted.
The issue with coffeescript is that it uses the opposite syntax to JS - `in` for arrays instead of objects. ES6 introduces the `of` keyword for real iterators so i don't really want to use that for either of them. It's tricky. There are other options but they're verbose every element as key, value from arr { console.log(key, value); } every property as key, value from obj { console.log(key, value); }
Thoughts on this? every [key, value] from arr { console.log(key, value); } every {key, value} from obj { console.log(key, value); } every [key] from arr { console.log(key); } every {_, value} from obj { console.log(value); } Looks a bit cramped to me but I get the impression that array comprehension is one of the major reasons that people use Coffeescript, so perhaps it's not too much trouble? There's also the issue…
fast-each [value] from arr {
}
fast-each {value} from obj {
}
fast-each [value, key] from arr {
}
fast-each {value, key} from obj {
}
The disadvantage is that this looks like array comprehension but isn't.Alternative:
fast-properties key, value from obj {
}
fast-elements index, value from arr {
}
fast-properties value from obj {
}
fast-elements value from arr {
}