Add a Conway’s-Game-of-Life example#14
Conversation
af4c97a to
ebff6e3
Compare
Hits the worker for every frame, which will perhaps be impressive.
…oard to 100x100. This lets us get boards over 44x44 to work in Viceroy, which has some URL-length limits.
ebff6e3 to
f0d840f
Compare
28fps vs. 9 Other measurements, for posterity, on my M3 Max: 57fps: Flask, 44x44, compression 34fps: Viceroy, 44x44, compression 34fps Viceroy, 44x44, no compression The above 2 show compression doesn't have a speed effect. So we keep it in case network IO is slow. Or in case someone is on MS Edge, which has a 2048b URL-length limit. 40fps: Flask, 100x100, compression 9fps: Viceroy, 100x100, compression
f0d840f to
4b604ea
Compare
|
|
||
| @app.route("/") | ||
| def root(): | ||
| return """<!DOCTYPE html> |
There was a problem hiding this comment.
Hmmm, I was considering options for moving this out to a separate file -- I wonder if it could be worthwile as a feature to have wasiless (or a separate step using wasi-virt) allow for doing fs virtualization and bundling a directory and its contents to some mount point in the image.
Python would use wasi fs but the virtualization layer would satisfy whatever it tried to access via its bundling.
There was a problem hiding this comment.
I would like to look into whether importlib.resources could be made to work reasonably with componenize-py. That would be the ultimate in Pythonicness.
There was a problem hiding this comment.
Experimenting with this. So far, it looks promising. componentize-py is happy to accept packages.
There was a problem hiding this comment.
No luck with the naive approach. The files in the package aren't around, and there's no automatic workaround. Even trying to read the __init__.py that's cited in a traceback reveals that it isn't really there. The results of resources.read_text("game_of_life", "__init__.py"):
[2025-10-29 15:45:16,944] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/2/flask/app.py", line 1511, in wsgi_app
File "/2/flask/app.py", line 919, in full_dispatch_request
File "/2/flask/app.py", line 917, in full_dispatch_request
File "/2/flask/app.py", line 902, in dispatch_request
File "/0/game_of_life/__init__.py", line 113, in root
File "/python/importlib/resources/_functional.py", line 32, in read_text
File "/python/pathlib/__init__.py", line 792, in read_text
File "/python/pathlib/__init__.py", line 776, in open
FileNotFoundError: [Errno 44] No such file or directory: '/0/game_of_life/__init__.py'
posborne
left a comment
There was a problem hiding this comment.
Game board state to evolve in the path seems a bit hard to deal with but has the obvious benefit of potentially giving us starting seeds of a sort we could use as examples.
I could see it being nice to have a later version of this allow for setting a fixed frame rate for more consistent animation with the option of going full beans.
|
Thanks for the quick review! The framerate is actually capped at whatever the browser chooses to do, typically 60Hz. But sure, one could add a slider or what-have-you. |
|
Putting game board state in the URL is mainly a nod to semantics: GET is conventionally cacheable, idempotent, not expected to mutate any state, etc. Unfortunately, it doesn't permit any request body, which is where I would rather have put the big board data! I experimented with PUT, which has weird base semantics for this case but the same idempotency, but I ran into (probably solveable) trouble with the JS API. Everything but Edge has plenty of URL space for the board at up to around 256x256, so I let it lie for now. |
This shows off some of Fastly’s strengths w.r.t. Python in a plain visual way:
I imagine it's more representative of customer use cases than a heavy web app: quick computations that make a decision and ditch. Plus, blinkenlights!