QRC - Performance
-
Hi,
This is more of a generic question.
QRC - Qt Resource Files increases the build time. Because it has to call run rcc compiler and generate qrc file.
When a system which has 100's of images, we can see a performance impact to the build.The benefit that we get is, accessing the resource directly without any path because qrc knows the path.
Instead I can write a function that can give me the path for resources directory and I can access the resources.
Why such performance impact system is there inside Qt?
I would like to understand the interesting part of QRC.
Thanks,
Kumara -
When using a path to resources in a directory you need to bundle these resources with your app and somehow make sure they are there.
Also you need to be careful to use proper relative paths and dynamically check the location of your executable because it can be run with arbitrary working directory that will mess your paths. This can be a heavy burden on maintenance and deployment.
On the other hand these files are not part of your solution so they have no impact on your build time or executable file.With qrc it's a completely different story. Qt resources are not external files. Instead they are embedded inside your executable file so all the deployment and paths problems go away. The down side is that they increase build times and executable size. Here's why. rcc compiler takes the qrc file, reads every path listed there and for every file it opens it and generates a c++ string representation of it. All these strings are then placed in an ordinary .cpp file and given a symbolic name. Open the generated
qrc_yourname.cpp
file to see what I mean. This generated file is then compiled and linked as any other c++ file in your solution.Since you have a lot of images, generating that .cpp file and then parsing, compiling and linking it will take a lot of time. This is true of any other large c++ file.
It is usually good to keep your resources size small - only embed small resources like icons your app may need or some textual or configuration files. Stuff like that. For large resources like movies, large number of images or sounds it is usually better to bundle them as external resources.Another solution, if you want to have the best of both worlds, is to compile the resources as a separate dll library and then load it at runtime. Here are the docs on this topic.
This way you will only have to compile the dll again when your resources change, which won't affect the rest of your build time, but you will keep the nice resource paths that you get with qrc. -
@Chris-Kawa This is excellent Chris!
I have not thought about such hybrid way.
I am going to give a try.
Thank you very much for the very clear explanation..
--Kumara