Optimize Kuromoji inner loop - rewrite ConnectionCosts.get() method [LUCENE-3935]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
I've been profiling Kuromoji, and not very surprisingly, method `ConnectionCosts.get(int forwardId, int backwardId)` that looks up costs in the Viterbi is called many many times and contributes to more processing time than I had expected.
This method is currently backed by a `short[][]`. This data stored here structure is a two dimensional array with both dimensions being fixed with 1316 elements in each dimension. (The data is `matrix.def` in MeCab-IPADIC.)
We can rewrite this to use a single one-dimensional array instead, and we will at least save one bounds check, a pointer reference, and we should also get much better cache utilization since this structure is likely to be in very local CPU cache.
I think this will be a nice optimization. Working on it...
---
Migrated from [LUCENE-3935](https://issues.apache.org/jira/browse/LUCENE-3935) by Christian Moen (@cmoen), updated Mar 30 2012
Attachments: [LUCENE-3935.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-3935/LUCENE-3935.patch)
Contributor guide
Research direction
Start at ConnectionCosts.get(int forwardId, int backwardId) and inspect its short[][] backing data alongside matrix.def. Compare the current representation with the proposed one-dimensional layout, then verify that Kuromoji’s Viterbi cost lookups still work and that the optimization improves the profiled hot path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- performance, search
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100