Perf: Better cache hit for `std::fs::canonicalize` and `std::fs::metadata`
Boshen opened this issue · comments
Both std::fs::canonicalize
and std::fs::metadata
are slow syscalls as they need to follow and resolve symlinks.
We can probably avoid a lot of these calls by normalizing and caching as much as possible.
For example, std::fs::metadata
is currently being called with such paths:
"/benchcases/three/src/copy1/./math/Color.js"
"/benchcases/three/src/copy1/core/../math/Color.js"
"/benchcases/three/src/copy1/extras/core/../../math/Color.js"
"/benchcases/three/src/copy1/helpers/../math/Color.js"
"/benchcases/three/src/copy1/lights/../math/Color.js"
"/benchcases/three/src/copy1/loaders/../math/Color.js"
"/benchcases/three/src/copy1/materials/../math/Color.js"
"/benchcases/three/src/copy1/renderers/shaders/../../math/Color.js"
"/benchcases/three/src/copy1/renderers/webgl/../../math/Color.js"
"/benchcases/three/src/copy1/scenes/../math/Color.js"
But only 1 call should exist because we can normalize and cache these paths prior to the call.
std::fs::canonicalize
will be harder to cache and normalize, but should be doable ;-)