Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add built-in query object caching for reuse in the multiple queries with the same query string #16

Closed
zhengchun opened this issue Oct 5, 2019 · 4 comments

Comments

@zhengchun
Copy link
Contributor

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
Copy link
Contributor

subsr97 commented Oct 27, 2019

@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
Copy link
Contributor Author

zhengchun commented Oct 31, 2019

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
Copy link
Contributor Author

zhengchun commented Nov 9, 2019

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

@zhengchun
Copy link
Contributor Author

# Add XPath selector object caching feature 14e3905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants