Task for performance improvements: ⚓ T15245 Performance improvements plans for Resource Rewrite
Two MRs in progress (one nearly finished, one still needs work):
Draft: Improve performance of query in KisTagResourceModel (!1302) · Merge requests · Graphics / Krita · GitLab (nearly finished)
Draft: Tag and untag multiple resources at once (!1312) · Merge requests · Graphics / Krita · GitLab (still needs work, but the main coding is done, at least for the tagResource() and untagResource()).
From what we (me and @Grum999) achieved so far is:
-
~4xspeed improvements in the first MR - even up to
~140x!!! speed improvements when tagging all resources at once (such big number was of course only when I was tagging all Rakurri’s brushes at once and it was I think already an 8th tag or something - but it went from 6 minutes of waiting (!) to just a little while).
(those speed improvements will combine, since the changes are independent)
And in case someone wonders why it wasn’t done like that from the get go… well, one of the lessons programmers learn is to never optimize too early (it’s called premature optimization if you want to look it up). The CPU is really fast; quite often the program just waits for the user to do something, not the other way around. Unless you know for a fact something will be used huge amounts of times, it’s best to write it in the simplest possible form (especially in GUI code - CPU is much faster than human’s reflexes or time sense). Otherwise it will probably turn out that you spent effort, time or other resources on making something just 1ms faster, even when it was already instant for the user. Often, the optimized code is longer and more complex (like in this case), and when it’s more complex, it’s more likely to contain bugs.
For comparison, I was working on those optimization and I think at least two people told me that it would be a good idea to move query->prepare() into a different place so it’s run only once instead of every time. As an idea, it’s not bad, but when I checked how much time it actually takes… using the numbers I have on hand, it took only 1ms, when the whole operation took 7527ms. So… I don’t think it’s worth spending time to gain just 1ms there 