[Userscript] ConfusionGuesser

Version 1.14 patch-notes:

Performance improvement for one-letter answers with fuzzy search disabled

With fuzzy search disabled, I just searched for all meanings that start with the given string. This led to a huge number of results when searching for very short strings (e.g. ~800 results for “a”). As a result, you would get hundreds of worthless guesses after entering “a” as an answer to a meaning question. Such a high number of guesses also leads to noticeable lag.

To prevent this, I switch to only considering exact matches if the previous method returns more than 16 results.

Small performance improvements for "Levenshtein distance" function

When writing the ConfusionGuesser script I tried to avoid using for-loops and instead used forEach(), map(), filter(), reduce(), …
Sadly, my “Levenshtein distance” function was extremely slow compared to a version using for-loops (tested on Chromium), so I’m now using for-loops in that function.

An interesting discovery I made in my experiments:

Array initialization
console.time("new Array => fill => map");
for (let i = 0; i < 1000; i++) {
	let d = new Array(1000).fill(null).map((a, j) => j);
console.timeEnd("new Array => fill => map");

for (let i = 0; i < 1000; i++) {
	let d = Array.from({length: 1000}, (a, j) => j);

for (let i = 0; i < 1000; i++) {
	let d = [];
	for (let j = 0; j < 1000; j++) d[j] = j;

Result in Microsoft Edge (Chromium):

new Array => fill => map: 16.60595703125 ms
Array.from: 75.56396484375 ms
for-loop: 7.5732421875 ms

Result in Firefox:

new Array => fill => map: 29ms
Array.from: 16ms
for-loop: 22ms

Chromium is awful at Array.from()! :open_mouth: Until now I had used Array.from() in my “Levenshtein distance” function, but now I’m just using a for-loop.

Please let me know if something doesn’t work.
Link to previous script version for downgrading in case version 1.14 doesn’t work for you