Skip to content

Optimize Conway with a Summed Area Table#436

Merged
chrisib merged 4 commits intoAllen-Synthesis:mainfrom
chrisib:conway-sat
Jun 6, 2025
Merged

Optimize Conway with a Summed Area Table#436
chrisib merged 4 commits intoAllen-Synthesis:mainfrom
chrisib:conway-sat

Conversation

@chrisib
Copy link
Copy Markdown
Collaborator

@chrisib chrisib commented May 31, 2025

Simple performance optimization for Conway to use a Summed Area Table instead of iterating through the neighbourhoods of changed pixels. This should keep the framerate more stable.

Replaces #435, though the multi-threaded approach may be reintroduced later.

@chrisib
Copy link
Copy Markdown
Collaborator Author

chrisib commented Jun 4, 2025

Debugging a very strange problem that seems to occur after a few hours of continuous use:

45061: 'bool' object has no attribute 'field_sum'
Traceback (most recent call last):
  File "/lib/bootloader.py", line 186, in main
  File "/lib/contrib/conway.py", line 348, in main
  File "/lib/contrib/conway.py", line 271, in tick
  File "/lib/contrib/conway.py", line 219, in sum_cells
AttributeError: 'bool' object has no attribute 'field_sum'

The stack trace calls are

conway.py", line 348, in main: self.tick()
conway.py", line 271, in tick: num_neighbours = self.sum_cells(top, left, bottom, right)
conway.py", line 219, in sum_cells: a = self.field_sum[start_row - 1][start_col - 1]

It's consistently that line that breaks, but I haven't succeeded in any debugging inspections yet. Launching from the intepreter:

>>> from contrib.conway import Conway
>>> c = Conway()
>>> c.main()
...
AttributeError: 'bool' object has no attribute 'field_sum'

re-running the offending function:

>>> c.tick()

works fine. So it seems to be some sort of runtime memory issue? Maybe there's a pointer that's going squirrely? Something is going wrong, but I haven't figured out exactly what or why yet.

@chrisib
Copy link
Copy Markdown
Collaborator Author

chrisib commented Jun 4, 2025

Was using uPython 1.24.1, so let's see if it goes away after upgrading to 1.25.0...

@chrisib
Copy link
Copy Markdown
Collaborator Author

chrisib commented Jun 4, 2025

Ran it overnight with 1.25.0 and the issue didn't reoccur. Frustrating that I can't figure out what happened, but it seems to be fixed.

@chrisib chrisib merged commit db51c97 into Allen-Synthesis:main Jun 6, 2025
3 checks passed
@chrisib chrisib deleted the conway-sat branch June 6, 2025 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant