Why is there a huge performance difference between embedding and using the Viewer API?

Hi all,

I have an interesting problem.
The same model, two different methods:

1: Embedding. Works fine.
2: Viewer API. Unusable due to the low frame rate.

Am I doing something wrong or is this just the way it works?

Thanks,
Ed

Sketchfab uses a few extra, undocumented init parameters that influence performance:

merge_materials: 1,
material_packing: 1,
graph_optimizer: 1,

I’d first add the graph optimizer and see if that helps.

3 Likes

I saw my project come crashing down… you just saved it.

The graph_optimizer: 1, did the trick. Thanks a lot Klaas. :pray:

@Sketchfab
I would say it’s about time someone documents this!

2 Likes

Embedding a resource, such as a video or image, directly into a web page can consume more resources and cause slower loading times compared to using the Viewer API. The Viewer API allows the resource to be loaded on-demand when needed, reducing the initial load time and resource consumption.

@MarcusCaden I believe that embedding using an iframe and using the viewer API technically is actually the same thing. But it’s true that embedding a model in a webpage that automatically loads, can increase loading time of the page as a whole. This is something to consider, especially with ecommerce applications.

You can avoid automatically loading the model with an embed parameter (or the equivalent viewer API init parameter).

<iframe 
  src="https://sketchfab.com/models/34dca831d4654a65a4f2eeee90e3a1a6/embed?autostart=0"
></iframe>

The autostart=0 will not start the model when the page this iframe is embedded on, loads. Though, omitting this parameter has the same effect, as not-loading the model is the default behavior.
The viewer API init parameter (Viewer API - Initialization - Sketchfab) is called the same, and has the same effect.

I believe what @CSMajorBoris is referring to is the difference in performance of the model itself after it has loaded. A model can perform badly when there are many objects or materials. On Sketchfab.com objects are automatically merged by the model viewer. If you embed the model yourself, you can replicate that optimization with the graph_optimizer: 1 init parameter. Or you can merge all objects int a single object before uploading of course.