jsdom icon indicating copy to clipboard operation
jsdom copied to clipboard

Performance of appending option to select

Open TheHound opened this issue 3 years ago • 1 comments

Previous implementation of adding 'option' elements to 'select' elements caused an '(N*N/2)' issue where all previous elements would be added to an array to find either the last selected or first non disabled. Now this logic is run on just the 'option' element being appended.

Before

yarn benchmark -suites=html
yarn run v1.22.19
$ node ./benchmark/runner -suites=html
# html/select/text #
jsdom  x 1.56 ops/sec ±3.61% (8 runs sampled)
Done in 11.29s.

After

yarn benchmark -suites=html
yarn run v1.22.19
$ node ./benchmark/runner -suites=html
# html/select/text #
jsdom  x 10.15 ops/sec ±6.53% (31 runs sampled)
Done in 7.23s.

Discovered this when I passed some html with a select with 20k option elements to JDSOM.

First pass at a fix and first time writing anything for nodejs so any and all feedback welcome including this not being the right way to solve the problem.

TheHound avatar Jul 23 '22 13:07 TheHound

Will get on that now - once done will amend commit unless I hear otherwise (i.e. to create a new commit)

TheHound avatar Jul 24 '22 12:07 TheHound

@TheHound This broke HTMLSelectElement.selectedOptions if HTMLOptionElement.selected is used: https://github.com/jsdom/jsdom/issues/3476

Revert in progress in https://github.com/jsdom/jsdom/pull/3475

Would be nice to reland with the new test passing though.

eps1lon avatar Dec 29 '22 12:12 eps1lon