Create a volume and run any pnpm operations only in the volume. Make sure pnpm uses only the volume and doesn’t do silly things like trying to write temporary files to /tmp (it’s in the rootfs so it’ll be slow).
Using these two tweaks I’ve seen installs of large npm projects take about 1 minute.
You could also use bun, it also results in a nice speedup but the fundamentals (writing a crapton of tiny files all over the disk) do require faster file I/O as covered above.