Meher Posted October 10, 2018 Share Posted October 10, 2018 Hi all, We have an application being build using babylonjs in which we are using an advanceddynamictexture to show a text block. We use the following line of code to create the texture: let textElementTexture: BABYLON.GUI.AdvancedDynamicTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(baseMeshforTextBlock); We also have a refresh key which updates the current scene and redraws the meshes again. We observed that refresh takes a long time due to the text blocks. On profiling further we found out that the above line of code takes around 35ms during the initial scene creation but when we do the refresh, the same line of code takes around 1900ms. We are not sure why there's this huge increase in time. Can someone help us understand this or provide any further guidance to figure out what's causing this? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted October 10, 2018 Share Posted October 10, 2018 Hello, this sounds pretty strange indeed. Could you create a repro in the playground so that we can all help you to troubleshoot the issue ? Quote Link to comment Share on other sites More sharing options...
Meher Posted October 10, 2018 Author Share Posted October 10, 2018 Hi Sebavan, We created a repro similar to the issue we are seeing. You can find it at: https://www.babylonjs-playground.com/#0AZUVK#5. This prints the time it takes to add the text to the console. You can use 'r' key to refresh which will basically add the text again. We observed another thing that as you keep pressing 'r', the time also keeps increasing. From our investigations, it seems like as the complexity of the scene increases, the time it takes also increases proportionately. The scene we have is pretty complex and we believe that's what is causing the rapid increase. But, we're still not able to explain why it's increasing in the first place. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted October 10, 2018 Share Posted October 10, 2018 Thx for the repro I am looking into it. Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 10, 2018 Share Posted October 10, 2018 Have to wait for Sebavan to see what the issue is with the code. Here is an alternative that does not use the console or re-create the plane, no increase in time https://www.babylonjs-playground.com/#0AZUVK#9 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted October 10, 2018 Share Posted October 10, 2018 @Meher, this comes from the list of objects in the scene getting bigger and bigger. You can clear them out by changing your dispose to plane.dispose(false, true); to ensure it disposes the related objects as well. https://www.babylonjs-playground.com/#0AZUVK#13 Quote Link to comment Share on other sites More sharing options...
Meher Posted October 10, 2018 Author Share Posted October 10, 2018 @Sebavan, thanks for the update. But there is one other issue in this. If you reduce the number of boxes in the playground demo from 10,000 (to say 10), the time also decreases. This clearly goes to show that the total number of objects in the scene is affecting the time taken for creating this object. This really will be an issue in our case since our scene is pretty heavy and as a result, it's taking around 1.8s to add the label. Is there any way to avoid this issue or to optimize the time? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted October 10, 2018 Share Posted October 10, 2018 Adding @deltakosh as I wonder if the latest optim around dispose and create and list management would adress this issue ? Quote Link to comment Share on other sites More sharing options...
Guest Posted October 10, 2018 Share Posted October 10, 2018 Hello, the reason why it is slow is because the system needs to go through all submeshes after you added a texture to make sure the shaders are flagged as dirty. You can turn this mechanism off like that: http://doc.babylonjs.com/how_to/optimizing_your_scene#blocking-the-dirty-mechanism Demo: https://www.babylonjs-playground.com/#0AZUVK#15 (see line #39) Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 10, 2018 Share Posted October 10, 2018 Just out of curiosity, does your project require label recreation rather than only changing the text string? Quote Link to comment Share on other sites More sharing options...
Meher Posted October 15, 2018 Author Share Posted October 15, 2018 @JohnK, yes we will need to recreate the label and not just change the text. @Deltakosh, thanks for this optimization but this seems to be introduced in 3.3.0, while we are still on 3.2.0. We will try this once we move to the newer version soon. Quote Link to comment Share on other sites More sharing options...
Guest Posted October 15, 2018 Share Posted October 15, 2018 Yep it is in 3.3.0 So you can directly jump to this one (or you can hack your version to add my change as well ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.