Type: New Feature
Resolution: Won't Fix
Affects Version/s: None
Fix Version/s: None
Towards eeking absolute best search performance, and after seeing the
Java ghosts in
LUCENE-1575, I decided to build a simple prototype
source code specializer for Lucene's searches.
The idea is to write dynamic Java code, specialized to run a very
specific query context (eg TermQuery, collecting top N by field, no
filter, no deletions), compile that Java code, and run it.
Here're the performance gains when compared to trunk:
|Query||Sort||Filt||Deletes||Scoring||Hits||QPS (base)||QPS (new)||%|
Those tests were run on a 19M doc wikipedia index (splitting each
Wikipedia doc @ ~1024 chars), on Linux, Java 1.6.0_10
But: it only works with TermQuery for now; it's just a start.
It should be easy for others to run this test:
- apply patch
- cd contrib/benchmark
- run python -u bench.py -delindex </path/to/index/with/deletes>
(You can leave off one of -delindex or -nodelindex and it'll skip
For each test, bench.py generates a single Java source file that runs
that one query; you can open
to see it. I'll attach an example. It writes "results.txt", in Jira
table format, which you should be able to copy/paste back here.
The specializer uses pretty much every search speedup I can think of
– the ones from
LUCENE-1575 (to score or not, to maxScore or not),
the ones suggested in the spinoff
LUCENE-1593 (pre-fill w/ sentinels,
don't use docID for tie breaking),
LUCENE-1536 (random access
filters). It bypasses TermDocs and interacts directly with the
IndexInput, and with BitVector for deletions. It directly folds in
the collector, if possible. A filter if used must be random access,
and is assumed to pre-multiply-in the deleted docs.
- I only handle TermQuery. I'd like to add others over time...
- It can collect by score, or single field (with the 3 scoring
LUCENE-1575). It can't do reverse field sort nor
multi-field sort now.
- The auto-gen code (gen.py) is rather hideous. It could use some
serious refactoring, etc.; I think we could get it to the point
where each Query can gen its own specialized code, maybe. It also
needs to be eventually ported to Java.
- The script runs old, then new, then checks that the topN results
are identical, and aborts if not. So I'm pretty sure the
specialized code is working correctly, for the cases I'm testing.
- The patch includes a few small changes to core, mostly to open up
package protected APIs so I can access stuff
I think this is an interesting effort for several reasons:
- It gives us a best-case upper bound performance we can expect from
Lucene's normal search classes (minus algorithmic improvements eg
PFOR) because it makes life as easy as possible on the
compiler/JRE to convert to assembly.
- We can spin out optimization ideas from this back into the core
LUCENE-1593already has one example), and prioritize. EG I
think given these results, optimizing for filters that support
random-access API is important. As we fold speedups back into
core, the gains from specialization will naturally decrease.
- Eventually (maybe, eg as a future "experimental" module) this can
be used in production as a simple "search wrapper". Ie, for a
given query, the specializer is checked. If the query "matches"
what the specializer can handle, then the specialized code is run;
else we fallback to Lucene core. Likely one would pre-compile the
space of all specializations, or we could compile java-on-the-fly
(eg what a JSP source does when it's changed) but I'm not sure how
costly/portable that is.
|Workflow||jira [ 12460546 ]||Default workflow, editable Closed status [ 12562629 ]|
|Workflow||Default workflow, editable Closed status [ 12562629 ]||jira [ 12583576 ]|
|Status||Open [ 1 ]||Resolved [ 5 ]|
|Resolution||Won't Fix [ 2 ]|