;LCSsize"aababcabcdabcaba" "eabcde"; // 4
You can get more performance if you switch to typed arrays like Uint8Array, Uint16Array, and instantiate only one instance of LCS class:
;const rawFiles =// Uint16Array of char codes in file_1.txt// ...// Uint16Array of char codes in file_n.txt;const maxSize = Math;const lcs = maxSize ; // in this way you reuse once allocated memory for every lcs.size() callfor let i = 0; i < rawFileslength; i++for let j = 0; j < i; j++const a b = rawFilesj rawFilesi;console;}
Please always make sure you don't mix types of arguments to
e.g. if you start passing typed arrays, do not pass strings anymore and vice versa.
Otherwise, you risk getting
size() function deoptimized by V8.
- At the moment, it can calculate only size of the longest common substring, not the string itself.
- Processing two 3,000-char strings takes under 2 seconds, however, memory consumption still can be improved a bit, from
O(min(r, n))with a little pull request. Performance improvements are very welcome!