Bug 129037 - BASIC: Selecting items in a visible list box in a dialog is very slow
Summary: BASIC: Selecting items in a visible list box in a dialog is very slow
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Caolán McNamara
URL:
Whiteboard: target:6.5.0
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-26 11:19 UTC by Mike Kaganski
Modified: 2019-11-27 09:12 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
A sample library for listbox item selection testing, packed as extension (2.25 KB, application/vnd.openofficeorg.extension)
2019-11-26 11:19 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2019-11-26 11:19:58 UTC
Created attachment 156124 [details]
A sample library for listbox item selection testing, packed as extension

Having a list box with many elements, and running code like

	Dim selItems(1000)
	For i = lBound(selItems) To uBound(selItems)
		selItems(i) = i
	Next i
	oListBox.selectItemsPos(selItems, true)

is very slow, especially compared to doing the same with the list box hidden (i.e., the call to selectItemsPos wrapped into calls to setVisible(false)...setVisible(true)).

In debug build, the process of the selection is actually visible, i.e. not an atomic operation, despite not multiple selectItemPos called, but a single selectItemsPos.

The attachment contains a basic module and a dialog in a library, exported as an extension for convenience; to test, install the OXT, and run Main in ListBoxTest/Module1. All three buttons below the list box in the dialog allow to deselect then re-select everything; they show elapsed time in seconds after the run.
Comment 1 Mike Kaganski 2019-11-26 11:32:32 UTC
Caolán, do you know if it's expected that XListBox::selectItemsPos behaves as multiple separate refreshing select operations?
Comment 2 Caolán McNamara 2019-11-26 14:06:48 UTC
selectItemsPos is implemented by VCLXListBox::selectItemsPos in toolkit/source/awt/vclxwindows.cxx and that loops over each index and calls ListBox::SelectEntryPos in a loop where SelectEntryPos is in vcl/source/control/listbox.cxx where the slow bits seems to be the very expensive CallEventListeners calls

checking VclEventId::ListboxSelect uses I don't think there is any use of the position argument passed in so I don't think that matters too much, consumers seem to just look up what is selected themselves, so its plausible that we could get away with a single CallEventListener in this scenario

https://gerrit.libreoffice.org/#/c/83771/
Comment 3 Caolán McNamara 2019-11-26 14:09:43 UTC
that would bring it down to 2 seconds for me and with https://gerrit.libreoffice.org/#/c/83774/ added on I get 0 seconds
Comment 4 Commit Notification 2019-11-26 20:12:56 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c8afb4000f178badaf63c2f38fd3fbc12ec832f3

tdf#129037 add a way to select multiple entries of a ListBox together

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2019-11-27 08:59:47 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/85578a6f9ca9dfb1e384d8d1f6edd8219a2ac493

tdf#129037 disable updates during multiselection

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Mike Kaganski 2019-11-27 09:12:48 UTC
Thank you very much Caolán!