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

Is list selection model too slow? #127

Open
tinchodias opened this issue Mar 20, 2024 · 4 comments
Open

Is list selection model too slow? #127

tinchodias opened this issue Mar 20, 2024 · 4 comments
Labels
question Further information is requested

Comments

@tinchodias
Copy link
Collaborator

tinchodias commented Mar 20, 2024

More than a second (MacBook Pro 2018) in selecting and deselecting 10000 items:

[| itemCount indices model |
itemCount := 10000.
indices := (1 to: itemCount) shuffled.
model := ToBasicListSelectionModel new.
indices do: [ :each | model selectIndex: each ].
indices do: [ :each | model deselectIndex: each ]] timeToRun asMilliSeconds  "1236"

However, this should be reported in Bloc repo: I profiled it and the main bottleneck is BlSelectionTree>>findOverlappingNeighbours: (belongs to Bloc project).

Screenshot 2024-03-20 at 18 28 27
@tinchodias tinchodias added the question Further information is requested label Mar 20, 2024
@tinchodias
Copy link
Collaborator Author

tinchodias commented Mar 20, 2024

As a very raw reference, simulating adding and removing the indices to a sorted list was 381ms:

[| itemCount indices model |
itemCount := 10000.
indices := (1 to: itemCount) shuffled.
selection := SortedCollection new.
indices do: [ :each | selection add: each ].
indices do: [ :each | selection remove: each ].
] timeToRun asMilliSeconds. "381"

And if sort was done only once at the end of selection, 43ms:

[| itemCount model sorted |
itemCount := 10000.
selection := OrderedCollection new.
indices do: [ :each | selection add: each ].
sorted := selection sorted.
indices do: [ :each | selection remove: each ].
] timeToRun asMilliSeconds.  "43"

But: I didn't analyse well the requirements of the API / invariants of Bloc selection to know if these examples are relevant as comparisions

@tinchodias
Copy link
Collaborator Author

In addition, we can analyse model's containsIndex::

itemCount := 10000.
indices := (1 to: itemCount) shuffled first: itemCount // 1.5.

" Model "
model := ToBasicListSelectionModel new.
indices do: [ :each | model selectIndex: each ].
[
	(1 to: itemCount) collect: [ :each | model containsIndex: each ].
] bench.
 "234 iterations in 5 seconds 7 milliseconds. 46.735 per second"

" Raw equivalent "
selection := Set new.
indices do: [ :each | selection add: each ].
[
	(1 to: itemCount) collect: [ :each | set includes: each ]
] bench.
 "6,484 iterations in 5 seconds 2 milliseconds. 1296.281 per second"

So, 46 executions per second in the model versus 1296 per second in a IdentitySet.

@plantec
Copy link
Collaborator

plantec commented Mar 21, 2024

yes, I've already observed the gain with identityDictionary. I've kept the BlMultipleSelection because of the interval selection feature. select:to: deselect:to, selectAll deselectAll

@tinchodias
Copy link
Collaborator Author

For the record: the original motivation for this issue was the output of profiling ToListElementStresser runInSDL, which showed around 46% of the time spent in selection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants