Today I tried MITK, and I noticed that DICOM import operation is order of magnitude faster there than in Slicer.
I tested this specific dataset: https://bit.ly/QIN-HN-137 on the same Linux system with the latest MITK package (2016.11) and the latest Slicer nightly. In MITK import of this dataset takes seconds, and in Slicer it is over 20 seconds. Considering both platforms are using the common set of components from CTK, is this behavior expected?
Yes, we should profile this. I suspect it’s either the tagCache using sqlite inefficiently or unneeded updates of the widget, but it would be good to know and fix.
It would be useful to keep the possibility of cancelling the import, so instead of removing the line, we could add a check which would only allow processing of events if at least a few seconds has passed since the last processing.
I agree, improvement of factor of 2 is great. If we could get to factor of 10 to be on par with CTK (and probably much closer to OsiriX), this would be perfect!
I did some profiling and about 50% of the time is spent in precacheTags, which is the part of the code that allows DICOMPlugins to save header values that they want to have fast access to in the future. This is being done as an sqlite transaction per-dicom object, but maybe there is a more efficient way to do this. Perhaps the tags can be stored in memory and then pushed to the database in one transaction when the parsing is finished (ideally the database transaction would be done in the background, but I don’t think that’s possible with sqlite).
The changes work without problems on Windows with Qt4.
I’ve made some speed measurements on loading 6 CTs:
With patched CTK of this PR: DICOM indexer has successfully processed 1554 files [255.59s]
If I comment out this->precacheTags(sopInstanceUID) call in ctkDICOMDatabase: DICOM indexer has successfully processed 1554 files [9.78s] !!!
There are some good tips on improving SQLite insert speed:
It seems that the most significant improvement (to 85 inserts/sec to 23000 inserts/sec) by using transactions.
After some investigation I’ve found a bug in how transactions is set up for inserting tagcache values. Actually, a transaction is created for the DICOM patient database and not for tag cache!
This change inctkDICOMDatabasePrivate::precacheTags decreases import time from 255 sec to 19 sec!