Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance : Is it better to import objects in package or individually?

Tags:

qt

qml

Let's say I have a bunch of c++ objects I want to expose to Qml.

I can imagine two way of doing so :

1st Method, One import statement for each object

qmlRegisterType<Object1>("my.package.object1", 1, 0, "Object1");
qmlRegisterType<Object2>("my.package.object2", 1, 0, "Object2");
qmlRegisterType<Object3>("my.package.object3", 1, 0, "Object3");
qmlRegisterType<Object4>("my.package.object4", 1, 0, "Object4");
...

And then in Qml we import what I need in each Component

import my.package.object2 1.0 
import my.package.object3 1.0

Object2 { Object3 { } }

2nd Method One import statement for all object:

qmlRegisterType<Object1>("my.package", 1, 0, "Object1");
qmlRegisterType<Object2>("my.package", 1, 0, "Object2");
qmlRegisterType<Object3>("my.package", 1, 0, "Object3");
qmlRegisterType<Object4>("my.package", 1, 0, "Object4");
...

Then in Qml we import all the objects in every Component that needs at least one of them

import my.package 1.0 

Object3 { 
    Object2 { ... } 
    Object1 { ... }
}

Clearly it is simpler (as long as it make sense) to group objects in package. And performance should not be your main concern.

In term of performance is one way better than the other ?

like image 445
BlueMagma Avatar asked Dec 28 '25 20:12

BlueMagma


1 Answers

I'm not 100% sure but I would say QML engine inspects modules when it finds an import statement, so if you put all classes in same modules, they will be found all at same time, but if you separate them, several module inspection will be needed.

So the real answer is :

  1. if you are using MOST of your objects in your app, put them in the same module so that with one single module inspection you have all of them (you have small overhead for objects you don't use, but you are saving the overhead of new module introspection).

  2. if you are using few items, separate them so that the ratio between "new module overhead" and the "unused object in module" is smaller

DISCLAIMER : anyway, we don't know the benchmarks of "new module inspection" overhead, neither the "unused object in module" overhead.

like image 180
TheBootroo Avatar answered Dec 30 '25 23:12

TheBootroo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!