Thanks for sharing those numbers; interesting I've never seen such a slowdown from a single insertion.
Quote:
With the sort:
The 1º search took 19281ms
2º: 99ms
3º: 58ms
4º: 22ms
5º: 19ms
then I indexed one document....
6º: 21360ms
7º: 21ms
That's an outrageous slowdown, not acceptable, I agree.
Two points to check:
1 - Do you have enough free memory? Could you log GC activity too, just to make sure it's not messing with the numbers.
I agree it seems unlikely but still if you're working close to the memory limits it will need to open a new segment, and free another.. GC might need to kick in with an expensive "stop the world" collection, if the extra segment in memory is too much to handle.
2 - Could you try upgrading Lucene from 3.1 to 3.3 ? Just to make sure we're not hitting an already fixed regression. It seems strange that this kicks in only when sorting.
Good news is that Hibernate Search 4 is introducing a NearRealTime mode, in which the IndexWriter doesn't need to flush after each commit and the readers can search also in the unflushed buffers from the writer.