Developer finds V8 lazy string hashing caused 30x sort slowdown in Electron app
A developer building a desktop file viewer discovered that sorting a million-row CSV took over a minute in Electron, despite the same code completing in half a second under Node.js. Profiling revealed the bottleneck was V8's lazy string hashing, which computes and caches a hash the first time a string is used as a Map key — a cost that proved significant across a million fresh strings in a memory-heavy renderer process. Replacing the string-keyed Map with a custom FNV-1a integer hash table eliminated the first-touch hashing overhead entirely. The fix also enabled caching integer rank keys per column and using a counting sort, removing per-comparison callbacks on repeat sorts. The developer noted uncertainty about why the same hashing cost does not appear as severe in a Node process and invited V8 internals experts to weigh in.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in