Do not rebuild the project database while destroying the project

Destroying a project cost more than loading it: on a 1000 folio project
--info reported its work done in 160 s but the process ran for 657 s, and
the difference was ~QETProject().

Timing each destructor puts 94 % of that teardown in
~QetGraphicsTableItem(), with the cost per table doubling as the project
grows (48 ms at 100 folios, 122 ms at 250). The database's own per-element
deletes are 1 % of it and linear; element and conductor teardown is linear.

A table destructor repairs the chain it belonged to, which relinks the
neighbouring tables, which assigns a model -- and one branch of
setPreviousTable() builds a fresh ProjectDBModel, whose copy constructor
calls setQuery(), which rebuilds the whole database. Destroying a 250 folio
project did that 12 times, for a project that is being thrown away.

So block the rebuild for the lifetime of the destructor, next to the
blockSignals(true) already there for the same reason. Nothing can observe
the result: the database is destroyed moments later as a member of the
project. Teardown drops about fivefold at every size measured -- 1.30 s to
0.26 s at 100 folios, 7.75 s to 1.73 s at 250, 19.92 s to 4.02 s at 400 --
and the number of full rebuilds in a run stops growing with project size.

Teardown is still superlinear, now dominated by
QetGraphicsTableItem::setUpColumnAndRowMinimumSize() measuring every cell of
the nomenclature each time a chain is relinked. That is left alone here.

--info stays byte identical on all 23 example projects, as do --export-bom,
--export-wires, --export-cables, --export-nets and --export-wiring.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6MRq2Ach1ogvnGcbuqNLr
This commit is contained in:
ispyisail
2026-09-12 17:26:40 +12:00
parent 956836458a
commit 73250bd746
+5
View File
@@ -160,6 +160,11 @@ QETProject::~QETProject()
//We block database signal to avoid hundreds of unnecessary emitted signal
//due to deletion (diagram, item, etc...) and as much update made in the not yet deleted things.
m_data_base.blockSignals(true);
//Same reasoning for the rebuild itself : destroying a table relinks
//the tables that were chained to it, which re-queries the database,
//which rebuilds it completely -- for a project that is on its way out.
//Nothing can observe the result : the database is destroyed with it.
m_data_base.setUpdateBlocked(true);
//Each time a diagram is deleted we also remove it from m_diagram_list
//because a lot of thing append during the destructor of a diagram class