Skip to content
  • Igor Kushnir's avatar
    ProjectFileDataProvider: clear items when no open projects left · 7477a4a1
    Igor Kushnir authored
    This change speeds up ProjectFileDataProvider::projectClosing() during
    KDevelop exit while a single project - kdevelop itself with a little
    more than 67 thousand files - is open, from 14 ms to 13 ms on average.
    In case of WebKit with its almost 320 thousand files as the single
    project - from 56 ms to 54 ms.
    
    When the last project is closed, there is a unique opportunity to free
    the memory of m_projectFiles without an extra allocation and without
    moving any ProjectFile objects. `m_projectFiles = {}` in place of
    `m_projectFiles.clear()` does not affect the execution time of
    projectClosing(). However releasing the memory can slow down the next
    call to ProjectFileDataProvider::projectOpened(). When the capacity of
    m_projectFiles is 0, projectOpened() has to repeatedly reallocate memory
    and move ProjectFile objects while iterating over the files of the just
    opened project. When all projects are closed, the user is likely exiting
    KDevelop (in which case `= {}` vs `clear()` does not matter) or is going
    to open another project soon.
    
    Even when a huge project with 300 thousand files is closed, at most mere
    15 MB could be released here, because m_projectFiles.capacity() would be
    at most 600 thousand and sizeof(ProjectFile) == 24.
    7477a4a1