Sketchfab Forum

Slowing down (freezing) when dynamically adding texture


(Madalin Berechet) #1

After the latest Sketchfab updates I have noticed a slowdown in the process of dynamically adding textures + updating the material.

I am using this to dynamically add a texture by .uid and to update the selected material:

`function changeTexture(fn, mat) {

api.addTexture(
    fn,
    function (err, textureUid) {
        materialToUpdate = materialHash[mat];
        materialToUpdate.channels.AlbedoPBR.texture.uid = textureUid;
        api.setMaterial(materialToUpdate, function () {
            console.log("material updated");
        });
    });}`

"fn" it's not a texture url but a generated "base64_image" as here: adding texture at runtime.

No slowdown when dynamically added texture is an image url, CORS enabled.

I need to optimize the process, so please let me know:

  1. is it a bandwith issue?

  2. Do I need more processing power (CPU / GPU)?

  3. What data format is suitable for this operation: base64_image, image/octet-stream, other? Do I need to use atob()/btoa() to decode/encode the string?

  4. It's better to save generated image on server and reload it from there?

I am using Chrome 56.0.2924.87 (64-bit) on windows.

Thanks.


#2

Not sure if it's related, but it looks like you're using an 800x800 px image? Non "power of 2 textures" can have a performance penalty.

Otherwise, I'm not sure how to help. @stephomi @paul_sketch ?


(Madalin Berechet) #3

@james
The canvas is 800 x 800 but actually the added texture (base64_image) has 1024x1024 because I scaled it by 1.28.
It works really better

But something continues to slow down the addTexture/setMaterial processes.
Could be a filter that limit the bandwith or number of accesses/second?
Was changed how Sketchfab treats textures (data structure)?

Thanks for the tip, It was useful.


(Madalin Berechet) #4

@james
The slowing dows acts as a smart filter that gradually inhibits access as they grow the requests.


(Stephomi) #5

It's a stupid issue on our side, we sort the images according to their name and for some reasons the name is the url (when calling addTexture) and our sorting algo speed is dependent of the name length... So obviously with base64 that's pretty terrible.

We'll fix that and try to ping you back.


(Rawinteractive) #6

Hi, can we have an update on this please? We're still seeing some major performance issues. Thanks.


(Stephomi) #7

Will be fixed on the next release, probably this week or the next week.

If it's urgent, you can upload the generated image on the server.

Sorry for the inconvenience.


(Madalin Berechet) #8

Fixed issue. Thanks!