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

Performance issue loading page with large number of selectpickers with relatively large number of options #1665

Closed
dw00001 opened this issue Mar 3, 2017 · 3 comments
Milestone

Comments

@dw00001
Copy link

dw00001 commented Mar 3, 2017

Summary: I am building a page that contains a large number of select elements (~200) each with a large number of options (~500). When using selectpicker for these elements the page has a very long load time and encounters the dreaded long running script warning on IE (performance is especially bad on IE). I made a few tweaks to reduce the load times and have attached the test with the tweaked code. Not sure if I have broken any functionality or overlooked any gotchas, but so far the changes seem to work correctly. I wanted to provide these changes to see if some variation could be incorporated into the project to provide similar performance improvement.

Environment details: I encountered the issue in chrome, firefox and IE. Performance is by far the worst in IE. You can see the versions of jquery, bootstrap, and bootstrap-select in the attached example.

I tried to add appropriate comments in the code to explain the changes, but here is a rough summary of the changes:

  1. changed code in render to only loop all options when select is multiple. Otherwise just jump to the selected option using native JS. Not a huge savings on chrome, but makes a bigger impact on IE.
  2. added a lazyLoadLiElements option. This option basically tells the selectpicker not to actually render the content on the dropdown menu when doing the inital load. A bunch of expensive operations are skipped and then we bind an event so that when the dropdown menu is activated for the first time, we actually render its contents. (it makes the the first time a little slower. it is hardly noticable on chrome. on IE it has a slight pause).
  3. As part of lazy load, I disabled the firing of the rendered event on initial loading. This event is super expensive on IE. Looking at the code, this may cause an issue if an invalid option was already selected when the page loaded. Perhaps this functionality can be implemented differently and you could provide an option to turn of this event for those that don't need it.

Instructions for running the test:

  1. extract contents of the attached zip file

  2. load slow.htm in your browser

  3. press "Create Select Fields(native)" button. This will create 200 native select elements each with 500 options on the page

  4. press "Selectpicker (orig)" button. This will change the native selects into selectpickers using the original implementation and report the run time.

  5. press reset (or refresh the page)

  6. press "Create Select Fields(native)" button. This will create 200 native select elements each with 500 options on the page

  7. press "Selectpicker(+perf changes)" button. This will change the native selects into selectpickers using the performance tweaks described above and report the run time.

In my testing, I was seeing around an 80% improvement on chrome and around a 95% improvement on IE.
selectpicker.zip

@ghost
Copy link

ghost commented Mar 7, 2017

Because we're on github with all of these PR things here's a PR with extracted changes from the archive :-)

We've tried it on some of our pages (worst scenarios) where we have 540 bootstrap-select components with 35 options each. With the changes above Chrome browser spends in init() function ~3s while without those changes it takes ~10s according CPU profiling.

ghost pushed a commit to MyTrucking/bootstrap-select that referenced this issue May 1, 2017
@caseyjhol caseyjhol added this to the v1.13.0 milestone Jul 26, 2017
silviomoreto pushed a commit that referenced this issue Apr 3, 2018
Following changes are extracted from the archive provided in #1665
silviomoreto added a commit that referenced this issue Apr 3, 2018
…lements

Lazy loading (extracted changes from provided archive, see issue #1665)
@caseyjhol caseyjhol modified the milestones: v1.13.0, v1.14.0 Aug 29, 2018
@grosser
Copy link

grosser commented Feb 1, 2019

could try lazy-loading #2187

caseyjhol added a commit that referenced this issue Mar 5, 2019
… if necessary (selectedTextFormat is "values" or is "count" and the number selected is below the limit). #1665
@caseyjhol caseyjhol modified the milestones: v1.14.0, v1.13.0 Mar 6, 2019
@caseyjhol
Copy link
Member

Most of your enhancements have been addressed in one way or another in the latest release - v1.13.6. Using your slow.htm page but with the latest version results in the whole page being loaded in under half a second in Chrome 72. Thanks for your contribution!

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

3 participants