-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
Description of the problem
We are parsing large data files which can contain up to tens of thousands of objects that we create ThreeJS (buffer)geometries for and finally merge them for efficient rendering. Profiling shows that the most costly part of loading (taking 25% of time in Chrome, somewhat less in Firefox) is actually generating the UUIDs for all the ThreeJS objects (the generateUUID() method from Math.js, due to the cost of string operations). In our case we do not need any of the serialization features and therefore don't really need the UUIDs either. Indeed, after swapping that function for a simple step ID implementation instead:
THREE.Math.generateUUID = function () {
var _id = 0;
return function generateStepID() {
return (_id++).toString();
};
}();
loading takes 25% less time (that can mean several seconds) and everything works as before.
This made me think if there could be a way to add functionality to select another ID generation method in case the application does not require UUIDs. Such as having a "THREE.Math.setIDGeneratorFunction()" or similar that could accept custom functions (or maybe also strings such as "UUID", "stepID" to choose from default implementation options).
This way there would be no need to manually overwrite an internally used ThreeJS function for better performance and others with similar needs could benefit if they find it in the docs. I would be happy to prepare a pull request for this. However, for robustness I think it would involve changing the "uuid" property of items to "id" to avoid the false implication it is a UUID in all cases, and also adding errors if UUID-reliant functions are attempted to be used with a non-UUID implementation. So maybe I am taking a wrong/overly complex approach to this?
Three.js version
- Dev
- r87
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS