jszhuyin
jszhuyin copied to clipboard
Optimize `JSZhuyinDataPackStorage#_getIncompleteMatchedSingleCodesInBlock`
Chrome DevTools Profiler has identified JSZhuyinDataPackStorage#_getIncompleteMatchedSingleCodesInBlock
as the top offender -- the for loop should be optimized if possible.
Fixing this and #25 probably means implementing the properly B-tree data structure...
The current approach can be found in no-linear-search
branch. The commits removes the linear for loop when search each of the block (i.e. the _getIncompleteMatchedSingleCodesInBlock
function stated on the title of the issue), and search all the partial matching sounds by generate a list of matched completed sounds first.
Unfortunately, per benchmark test, that actually makes it slower by ~35%.
The next thing to try would be try to reduce the list of completed sounds, since there are 4095 combinations yet in our database per my last investigation there are only around 1001 sounds exists. Implement that might reduce 76% of our call to the _searchBlock()
functions.
B-tree probably won't help here since it only re-orders the values within the linear array, not actually change how we search things within it. But that could still be the next thing to try if the previous attempt proves unhelpful.