stefanseifert commented on PR #20:
URL:
https://github.com/apache/sling-org-apache-sling-testing-sling-mock-oak/pull/20#issuecomment-7103819999
thanks - this feature looks fine for the "standard use case" - oak-luence is
not on the classpath at all.
here is an AI feedback for the use case when "oak-lucene" is on the
classpath, but maybe not used. i've not checked the details, i'm not deep
enough into the oak codebase. please check if this is relevant.
---
### Commits get slower when `oak-lucene` is on the classpath but no Lucene
index is defined
**Summary**
When `oak-lucene` is on the test classpath, every commit runs one extra full
index update pass, even if no Lucene index exists. This also changes the
repository content: the node counter index (`/oak:index/counter/:index`) gets
filled, which doesn't happen on master. The README says `oak-lucene` also
enables the feature when it comes in transitively, so some projects will get
this without adding the dependency on purpose.
When `oak-lucene` is not on the classpath, I measured no slowdown compared
to master.
**Root cause**
Oak's standard initial content (`InitialContent`) creates
`/oak:index/counter` with `type="counter"` and `async="async"`.
`SynchronousAsyncIndexHook.collectAsyncLanes()` reads the `async` property
of every index definition, whatever its `type`. The root node changes in every
commit, so it always finds `/oak:index/counter`, and the `async` lane is always
selected. As a result, every commit runs an extra
`new EditorHook(new IndexUpdateProvider(<all default index editors +
Lucene>, "async", false))`, which walks through all changes a second time.
**Measurements**
- Setup: in-memory `Oak`/`Jcr` set up the same way as
`OakMockSlingRepository`.
- Values: average ms over 15 rounds, after 5 warm-up rounds.
| variant | startup | 200 small commits (20 nodes each) | 1 bulk commit (6k
nodes) | 300 single-property updates |
|---|---|---|---|---|
| baseline (master behavior) | 14.6 | 72.6 | 71.7 | 29.7 |
| no oak-lucene (`LuceneIndexMissingWarning` only) | 14.3 | 70.4 | 70.1 |
29.4 |
| **oak-lucene present, no Lucene index defined** | 14.7 | **79.2** (+9%) |
**76.6** (+7%) | **36.1** (+22%) |
| oak-lucene present, lanes collected only from `type=lucene` definitions |
14.2 | 71.4 | 71.2 | 29.9 |
Counter index data (`/oak:index/counter/:index`) after the run:
- baseline: not present
- no oak-lucene: not present
- **oak-lucene present: present**
- `type=lucene` filter: not present
**Why the counter matters**
Oak's query planner uses the node counter to estimate query costs. So in
projects that only have `oak-lucene` transitively, query plans or traversal
warnings can differ from master, even though no Lucene index is used.
**Suggested fix**
Only collect async lanes from Lucene index definitions:
```java
for (ChildNodeEntry entry :
after.getChildNode(IndexConstants.INDEX_DEFINITIONS_NAME).getChildNodeEntries())
{
NodeState definition = entry.getNodeState();
if
(!LuceneIndexConstants.TYPE_LUCENE.equals(definition.getString(IndexConstants.TYPE_PROPERTY_NAME)))
{
continue;
}
PropertyState async =
definition.getProperty(IndexConstants.ASYNC_PROPERTY_NAME);
...
}
```
With this change, timing and counter state are the same as baseline (last
row of the table).
What still happens with the fix:
- If a Lucene index uses the `async` lane, the counter index (and any other
non-Lucene async index on that lane) is still updated in each commit. That's
fine, because the feature is then actually in use.
- Do **not** fix this by leaving `NodeCounterEditorProvider` out of the
composite. `IndexUpdate` would then report `Missing index provider of type
[counter]` and set `reindex=true` on `/oak:index/counter`.
**Test suggestion**
Add a test that checks that a commit doesn't run an async lane update when
no Lucene index definition exists, for example a unit test of `getAsyncLanes()`
on content that contains only the default `/oak:index/counter`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]