Speeding up work with large lists and lists of strings. Conditional compilation symbol TLIST_FAST.
In addition, with the conditional compilation symbol TLIST_FAST, the structure of the list and the algorithms for working with elements are changed in such a way as to provide a faster operation of adding new elements. At the same time, the additional UseBlocks property becomes available, which allows you to control the use of new list methods. The increase in speed occurs primarily due to the fact that the number of memory reallocation operations (with copying accumulated pointers to a new location in memory) decreases. More precisely, the reallocation of memory is no longer required at all, only new blocks of 256 elements per block are allocated as needed.
Unfortunately, the increase in performance at the stage of adding elements turns into a decrease in the speed of accessing the elements of the list. In the case when all the elements are used in the blocks, except for the last one, the reduction in the access speed is insignificant: the block index is calculated by the index (by simple division by 256), and after obtaining the pointer to the block from the continuous list of blocks, the required element can be retrieved. The worst result is obtained if, as a result of deleting or inserting elements somewhere in the middle or at the beginning of the list, incomplete blocks are formed. In this case, a longer algorithm is used to find the desired block and the index of the desired element in it, which requires enumeration of all blocks from the initial to the required block. It is somewhat optimized for the case of sequential access to elements,
To speed up the work with the "quick" list at the stage when its initial filling is completed, and then it is used only for accessing elements, it is required to ensure its "dense" filling, in which all blocks are completely filled in it (except, perhaps, the last ). To do this, just call the method OptimizeForReadcompaction of blocks.
Note that in the case when the TLIST_FAST symbol is defined in the project options, it also affects the string lists. TStrList, TStrListEx, TWStrList, TWStrListEx... In order to speed up their work after the initial filling, you should call their method OptimizeForReadwhich refers to the corresponding method of the inner list.