– Disclaimer –
This optimization requires more manual work and is error prone but isn’t this with most (big) performance improvements?
For it to really work you have to structure your code accordingly and flush explicitly.
Recently in our performance measurements of a medium sized Grails project we noticed a strange behavior: every time we executed the same query the time it took increased. It started with 40ms and every time it took 1 ms more. The query was simple like
The first thought: indexes! We looked at the database (a postgresql db) and we had indexes on the parent column.
Next: maybe the session cache got too large. But
session.clear() did not solve that problem.
Another post suggested using a HQL query. Changing to
Child.executeQuery("select new Child(c.name, c.parent) from Child c where parent=:parent", [parent: parent])
had no effect.
Finally after countless more attempts we tried:
And not even the query executed in constant time it was also 10x faster?!
The default flush mode in Grails is set to
Which means that before every query made the session is flushed. Every query regardless of the classes effected. The problem is known for hibernate but after 4! years it is still unresolved.
So my question here is: why did Grails chose AUTO as default?