Optimize KoID
Open, NormalPublic

Description

KoID is an ID with a translatable string associated with it. It's used all over the place as a way to uniquely identify things. Unfortunately the ID itself is a QString, which is not great for performance.

There are a number of ways this can be improved. A common one is to hash strings and use the result in code. The exact solution depends on what limitations are acceptable, so the first step is to figure out what use-cases we need to support.

These are the requirements of KoID I've gathered so far:

  1. Each ID has to be unique
  2. Each ID has to map to one translatable string
  3. Translatable strings do not have to be unique, i.e. multiple IDs can map to identical translatable strings
  4. IDs have to be deterministic within the same version; building and running Krita multiple times from the same source should produce identical IDs
  5. IDs have to be comparable and sortable
  6. KoID has to be serializable in a forward and backward compatible manner, i.e. writing an ID to disk in one version of Krita and loading it in another have to map to the same source ID definition
  7. KoID has to be QMetaType compatible (http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE)
  8. Runtime KoID creation has to be supported (?) [Note: This is based on usage where KoIDs are created from settings files. If those strings are known at compile time this requirement can be removed]
victorw created this task.Jul 22 2017, 9:40 AM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptJul 22 2017, 9:40 AM
victorw updated the task description. (Show Details)Jul 22 2017, 9:42 AM
woltherav moved this task from Backlog to Zeyelth on the Krita board.May 18 2018, 9:06 AM

Looking at the code base, there are two steps that should be taken before any radical change occurs:

  1. Move construction of KoIDs to separate include files so that no KoIDs are created after startup
  2. Directly use KoID instance from above include files, use a lookup if necessary

Once no KoID constructor is called after startup, we can start looking into KoID's actual implementation and ways to improve how KoIDs are defined.