Skip to content

PATH.normalize is incredibly expensive. #16858

@Aeodyn

Description

@Aeodyn

I profiled a WebGL Unity game that had analytics enabled, and by far the most expensive call chain was PATH.normalize and related, in particular because of the .join("/") call. Just replacing the body of normalize with if(path[0] === "/" && path[1] === "/") return path.slice(1); return path; fixed the constant stutters that I was looking at. I cannot stress enough how much of a performance increase this was. Checking if the string is already normalized should help immensely.

I'm sorry I don't have any hard statistics ready for you, but just profiling any Unity game that has frequent virtual FS access (as with Unity's analytics enabled) with the Firefox Profiler should show it immediately.

I'm unsure what version of Emscripten was used in the game I profiled, but PATH.normalize is completely unchanged relative to now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions