dart-lang / html

Dart port of html5lib. For parsing HTML/HTML5 with Dart. Works in the client and on the server.
https://pub.dev/packages/html
Other
277 stars 59 forks source link

feat: add `limit` parameter to `querySelectorAll` #168

Closed mzdm closed 7 months ago

mzdm commented 3 years ago

If you want only a first few results then having limit parameter is significantly faster than iterating wastefully the whole tree.

I've created a quick example with benchmark https://github.com/mzdm/dart_html_limit_perf_test

For example on this page https://en.wikipedia.org/wiki/Earth you would want to get first 4 title names. old way - document.querySelectorAll('.mw-headline').take(4).toList(); would take BenchHtml(RunTime): 81102.96 us. new way - document.querySelectorAll('.mw-headline', limit: 4); - would take BenchHtmlLimit(RunTime): 7417.951851851852 us. (~10x times less)

If this is OK approach then I can add some tests.

andy1xx8 commented 3 years ago

I would love to have this feature

mosuem commented 7 months ago

Closing this as it is stale and it is recommended to use package:web instead. Feel free to reopen in case you still want to land it!