Open source · September 28, 2026

One of nvm's shell functions just got ~140x faster

If you use nvm every day, one of its shell functions just got ~140x faster.

Then it got merged (PR #3912). Then it got released (nvm v0.40.8).

The change was actually pretty simple. nvm_tree_contains_path() was repeatedly calling dirname to walk up a directory path. I replaced that with an in-memory POSIX parent walk using shell parameter expansion.

And the benchmark: before, 16,274 ms. After, 115 ms. For 50 calls. That's roughly 141x faster.

And the part I like most: ~350 process forks → 0.

This function sits underneath nvm's path handling, including the checks it performs around Node version management and project directories. So the improvement isn't some new feature. It's just less process creation happening underneath the commands you're already using.

And now it's officially part of nvm v0.40.8, released under the Performance section.

Happy to be a small part of a project that's been around for years and is still being used every day.

Written by Thanniru Sai Teja. More writing.