3 ms·
Not your OP, but I've got stories! PhotoStructure is a non-trivial app written in TypeScript for both frontend and backend tasks. Coming from Scala, I initial
by mceachen 4y ago
Not your OP, but I've got stories!
PhotoStructure is a non-trivial app written in TypeScript for both frontend and backend tasks.
Coming from Scala, I initially used a lot of Array.map, Array.foreach, and, to handle things like Some/None/Either:
function map<T,U>(
maybe: <T|undefined>,
f: (t:T) => U
)
According to the V8 memory inspector, all those tiny fat-arrow functions can hammer the GC (presumably due to stack allocations and pulling in local context). Replacing large array iteration with for loops was a big win.
Also, handling large files with a streaming parser when possible, instead of reading them entirely into memory, another win.
Buffer concatenation may be faster by pushing read chunks onto an array, and joining the lot at the end, rather than incrementally appending with .concat.
When memoizing functions, if they themselves return functions, watch out for fat-arrows if you didn't need the caller's context (which may prevent gc from unexpectedly retained variables).
But the first step should always be to profile your app. You can't assert improvement without a baseline.