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

gfx_sort1 takes way too long on big matrices #54

Open
vifino opened this issue Jul 11, 2018 · 5 comments
Open

gfx_sort1 takes way too long on big matrices #54

vifino opened this issue Jul 11, 2018 · 5 comments
Assignees
Labels
enhancement Enhancement suggestions to the project.

Comments

@vifino
Copy link
Member

vifino commented Jul 11, 2018

It should probably try to finish in a fixed time - or at least similar times - when running on a different matrix size.

On my X200's display, it takes a long time, probably over a minute.

@vifino vifino added the bug Bugs or misbehaviour. label Jul 11, 2018
@vifino
Copy link
Member Author

vifino commented Jul 11, 2018

Actually, it's not consistent there either, now it's been running for ~5 minutes.

@cyriax0
Copy link
Contributor

cyriax0 commented Jul 18, 2018

That is to be expected.

The time for completion is highly dependent on display size. This is an inherent property of sorting algorithms.

Complexity of the algorithm

Bubblesort has a runtime of O(n^2) (see https://en.wikipedia.org/wiki/Bubble_sort#Performance).
The runtime of that algorithm should be similar, although the complexity analysis is somewhat more complex as the data depenencies are spread over the 2D space.

For the simple variant where only diagonals are sorted the complexity on an AxB LED Matrix should be O(max(A,B)^2). The Complex variant might have longer path lengths between the starting position of a pixel and the final position, but the complexity class should still be similar.

The expected number of frames should should be different as O(AB) locations are considered per step.
This should/could be measured but I expect something like omega(max(A,B)) and o(max(A,B)^2). frames. This is dependent on the maximal path length and stuff. Measuring should be doable as there exists already a framecounter.

Speedup Ideas

  • Eliminate the random selection of places to invert. Currently only randomly selected 25% of the locations are touched. This would change the look of the effect a bit.
  • Calculate multiple steps per frame. This assumes big displays are connected to big computers. If you're hitting a processing wall, this isn't an option.
  • Deactive module for big outputs Some variations are deactivated for big outputs. Alternatively everything is deactivated when the output matrix is ''too big''.

Conclusion

Getting on or near a target number of frames isn't feasible right now as the runtime depends on sorting mode and I'm too lazy to measure for future predictions. You might manually adjust the framerate or deactivate the module.

@cyriax0 cyriax0 added enhancement Enhancement suggestions to the project. and removed bug Bugs or misbehaviour. labels Jul 18, 2018
@cyriax0
Copy link
Contributor

cyriax0 commented Jul 18, 2018

It's not a bug. It's a feature/inherent property of the algorithm.

@vifino
Copy link
Member Author

vifino commented Jul 18, 2018

Sorry that I marked it as a bug, not an enhancement, my bad.

Yeah, I get it, I was thinking something like a frame limit, so it doesn't run for ages on big matrices and gives other modules a chance to run as well.

@orithena
Copy link
Collaborator

Another speedup idea: Scale a "sorting pixel" to multiple LEDs on higher resolutions; or, in other words, lower the resolution of the sorting matrix. E.g. 2x2 LEDs per "sorting pixel" on a 64x64 LED matrix, 3x3 on 96x96, 4x4 on 128x128 etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement suggestions to the project.
Projects
None yet
Development

No branches or pull requests

3 participants