4 ms·
To be fair, it's not obvious if you're not a JS expert: coming from some other language, you could naively assume that function call gets inlined, with no overh
by throwaway_yy2Di 12y ago
To be fair, it's not obvious if you're not a JS expert: coming from some other language, you could naively assume that function call gets inlined, with no overhead.
- k__ 12y agoA few months ago, I tried some image processing with JS and the canvas object (big Arrays). They have a structure like image[pixel].color What I found was, always traversing the object structure was much slower than putting every pixel color as an argument in a function, that gets called every iteration. So I had the impression, reasonable simple function, like a greyscale filter, get inlined by engines like V8.
- warfangle 12y agoYou probably would have been better off with typed arrays and fragment shaders, if you were going for performance.
- k__ 12y agoAren't the arrays produced by a canvas object typed?
- warfangle 12y agoYep, but they only become performant when you treat them as such instead of doing naive e.g. multiplication. See: https://hacks.mozilla.org/2011/12/faster-canvas-pixel-manipulation-with-typed-arrays/ https://hacks.mozilla.org/2011/12/faster-canvas-pixel-manipu...
- bzbarsky 12y agoLike any other compiler, function calls sometimes get inlined. And sometimes not. Depending on compiler heuristics of various sorts.