Performance optimization.

Issue #168 resolved
Roman Telezhynskyi repo owner created an issue

My last profiling showed that method

//setData copy data from container
void VContainer::setData(const VContainer &data)

is the most expensive.

This happens because each a tool have own the data copy. This help understand which object exists for this a tool. Each parsing (lite or full) update the data for each a tool.

Many C++ classes in Qt use implicit data sharing to maximize resource usage and minimize copying. Implicitly shared classes are both safe and efficient when passed as arguments, because only a pointer to the data is passed around, and the data is copied only if and when a function writes to it, i.e., copy-on-write.

Articles:
Implicit Sharing in Qt
Неявный и явный совместный доступ к данным в Qt

Implicit data sharing can be useful in this case, because each copy of the data contain same information with some new portions. Left only one question. How work implicit data sharing? I mean, what happens when we add new value. Will we copy whole structure? For example for QHash (use very often) documentation say:

This operation occurs in constant time, because QHash is implicitly shared. This makes returning a QHash from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes linear time.

This mean for us answer yes, we will copy whole QHash. But solution can be use implicit data sharing technology in classes VGObject, VDetail, VInternalVariable directly.

Comments (1)

  1. Log in to comment