jszhuyin icon indicating copy to clipboard operation
jszhuyin copied to clipboard

Optimize `JSZhuyinDataPackStorage#_getIncompleteMatchedSingleCodesInBlock`

Open timdream opened this issue 9 years ago • 2 comments

Chrome DevTools Profiler has identified JSZhuyinDataPackStorage#_getIncompleteMatchedSingleCodesInBlock as the top offender -- the for loop should be optimized if possible.

timdream avatar Dec 08 '15 14:12 timdream

Fixing this and #25 probably means implementing the properly B-tree data structure...

timdream avatar Oct 31 '16 10:10 timdream

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.

timdream avatar Jan 21 '17 08:01 timdream