add built-in query object caching for reuse in the multiple queries with the same query string
zhengchun opened this issue · 4 comments
zhengchun commented
htmlquery
provides new methods QuerySelector and QuerySelectorAll, We can use compiled query object to reuse and avoid recompile the XPath query expression, this will shorter query speed time and improve application performance.
subsr97 commented
@zhengchun
As I understand, you're suggesting to cache compiled XPath query expressions for use by FindOne
and Find
methods.
But wouldn't the overhead of maintaining a cache be greater than the overhead caused by recompiling XPath queries?
zhengchun commented
In fact, caching frequently used query objects can improve query performance. groupcache, I just caching Top N objects those the most frequent query object.
zhengchun commented
https://github.com/antchfx/htmlquery/blob/master/query_test.go#L47
goos: windows
goarch: amd64
pkg: github.com/antchfx/htmlquery
BenchmarkSelectorCache-4 20000000 55.2 ns/op
BenchmarkDisableSelectorCache-4 500000 3162 ns/op
PASS