Speed up name placement 1000x by using bitmaps to detect collisions#1
Open
makomk wants to merge 3 commits intoWorkVerbDesign:masterfrom
Open
Speed up name placement 1000x by using bitmaps to detect collisions#1makomk wants to merge 3 commits intoWorkVerbDesign:masterfrom
makomk wants to merge 3 commits intoWorkVerbDesign:masterfrom
Conversation
Instead of checking for collisions one pixel at a time, convert the occupied pixels to bitmaps stored as one long integer per line and compare them using shift-then-and. This isn't quite a thousand times faster, but it's close. Keep the old code as a final check.
We can get a decent speed-up when placing lots of names on an almost empty board by updating the existing backing bitmap directly, rather than recreating the whole thing again from the image. This is especially worthwhile if the slower, redundant pixel-by-pixel check for overlaps can be removed too.
Author
|
Huh. It looks like the name constipation issues I was seeing were made worse by a weird bug where totalEntries wasn't actually updated for subsequent names in a batch, I think due to SQLite making the result read-consistent with the query reading the names, so they were drawn too big. Stuff works a lot better after working around that. I'd definitely suggest checking for and dealing with this before you get any more big sub bombs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I managed to speed the name placement up by almost 1000x whilst still using PIL, standard Python, and exactly the same completely random placement. Instead of comparing one pixel at a time, I use PIL to convert the images to bitmaps with one bit per pixel that's in use then store them as one long integer per row, meaning I can just shift and AND the integers to test a whole row at once. Poopbutt's evil twin can still sometimes cause several minutes of constipation even with this speed improvement, but it really is a lot faster and not all that much more complicated.
For context, my last run of this placed all the unplaced names in the currently-uploaded version of the database in about three minutes on my desktop, though obviously this varies a lot depending on luck.