Skip to content

Conversation

elalish
Copy link
Contributor

@elalish elalish commented Oct 14, 2021

This may have been a problem for a while but I just noticed it when I was doing performance checks for another PR: The environment was getting generated completely before the GLB model was fetched. This is bad because fetching is generally the long-pole to getting our render up and is completely async compared to all the JS we run. Therefore we definitely want to start our fetch before any long, blocking JS functions. Generating the environment is one such long, blocking call. I've fixed it here in a slightly hacky way, but it's simple and non-dangerous.

To aid in debug, I also made a refactor I've been meaning to do for some time, which is to centralize our calls to ModelScene.isDirty into functions, so that it's easy to put console logs in to see what triggers rendering. I also discovered console.trace() which is awesome, because with one line I can see exactly what caused every re-render.

@elalish elalish self-assigned this Oct 14, 2021
@elalish elalish requested review from a user and samaneh-kazemi October 14, 2021 00:01
@@ -156,7 +156,9 @@ export default class TextureUtils extends EventDispatcher {
return this.skyboxCache.get(url)!;
}

private GenerateEnvironmentMap(scene: Scene) {
private async GenerateEnvironmentMap(scene: Scene, name: string) {
await timePasses();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the hack that actually made the difference. This zero-time await simply tosses the execution of this function to the end of the microtask stack, allowing other queued operations (like loading the src) to get ahead of it.

@elalish elalish merged commit ef0b6b6 into master Oct 14, 2021
@elalish elalish deleted the parallelEnvironment branch October 14, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant