This issue is for exploring an alternate FST encoding of Arcs as full-sized arrays so Arcs are addressed directly by label, avoiding binary search that we use today for arrays of Arcs. PR: https://github.com/apache/lucene-solr/pull/657
ant test passes. I added some unit tests that were helpful in uncovering bugs while
implementing which are more difficult to chase down when uncovered by the randomized testing we already do. They don't really test anything new; they're just more focused.
I'm not sure why, but ant precommit failed for me with:
I also got Test2BFST running (it was originally timing out due to excessive calls to ramBytesUsage(), which seems to have gotten slow), and it passed; that change isn't include here.
I timed lookups in FST via FSTEnum.seekExact in a unit test under various conditions.
A test of looking up existing words in a dictionary of ~170000 English words shows improvements; the numbers listed are % change in FST size, time to look up (FSTEnum.seekExact) words that are in the dict, and time to look up random strings that are not in the dict. The comparison is against the current codebase with the optimization disabled. A separate comparison of showed no significant change of the baseline (no opto applied) vs the current master FST impl with no code changes applied.
|+4, -6, -7||+18, -11, -8||+22, -11.5, -7|
The "load factor" used for those measurements controls when direct array arc encoding is used;
namely when the number of outgoing arcs was > load * (max label - min label).
The same test, with terms being a sequence of integers as strings shows a larger improvement, around 20% (load=4). This is presumably the best case for this delta, where every Arc is encoded as a direct lookup.
When random lowercase ASCII strings are used, a smaller improvement of around 4% is seen.
Testing w/luceneutil (wikimediumall) we see improvements mostly in the PKLookup case. Other results seem noisy, with perhaps a small improvment in some of the queries.
I ran LookupBenchmarkTest to see the impact on the suggesters which make heavy use of FSTs. Some show little or no improvement, but in some cases there are substantial gains.
The only change in the public FST API is that the Builder constructor now takes an additional
boolean ("useDirectArcAddressing") controlling whether or not this new optimization is
applied. However, FST's internal details are not really hidden, so in practice any change to its
encoding can have ripple effects in other classes.
This is because the FST decoding is repeated in several places in the code base, sometimes with
subtle variations: eg FST, FSTEnum, and fst.Util have very similar, but not shared, traversal code,
and there are a few other places this same or similar decoding algorithm appears as well (eg
blocktreeords codec). I do think it would be useful to make this code more DRY, and to hide the
traversal implementation within a single class (or at least in the package), but it seemed better to
do that separately. I also think there are possibilities for improving this encoding further, maybe
by encoding Arcs in contiguous blocks with gaps in between, but before attempting anything like
that, I think it would good to do that refactor to make the code in its current form easier to
understand and work with.