Repository navigation
audioeffects: each effect loads the first time it's used - #10
Merged
Merged
Conversation
`import audioeffects` imported all 45 effect modules, so a program that uses a reverb paid for every effect's code in RAM, and a firmware that freezes the package had to freeze all of it, about 400 KB of bytecode on an ESP32. Each class is now imported on first use, through the package's __getattr__. `from audioeffects import Reverb`, `audioeffects.Reverb`, `create()` and `ALL` work as before. A firmware can freeze only the effects it plays plus `__init__` and `_component`. One difference: on MicroPython, `from audioeffects import *` now brings in only the effects already used, since MicroPython's star import reads the module's names rather than `__all__`. Checked: tools/scoped_tests.py contract, tools/validate_api.py (45 effects), tests/parity/effects_library_smoke.py (45 classes, 325 patches, 0 failures) and flake8. On CPython and the unix MicroPython port, importing the package loads only _component, and importing Reverb and Chorus loads just those two.
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.
import audioeffectsimported all 45 effect modules. A program that uses one reverb paid for every effect's code in RAM, and a firmware that freezes the package had to freeze all of it, about 400 KB of bytecode on an ESP32.Each class is now imported on first use, through the package's
__getattr__.from audioeffects import Reverb,audioeffects.Reverb,create()andALLbehave as before. A firmware can freeze just the effects it plays, plus__init__and_component.One behaviour changes: on MicroPython,
from audioeffects import *now brings in only the effects already loaded, because MicroPython's star import reads the module's names rather than__all__. CPython's star import still loads everything.I ran
tools/scoped_tests.py contract,tools/validate_api.py(45 effects),tests/parity/effects_library_smoke.py(45 classes, 325 patches, 0 failures) and flake8. On CPython and the unix MicroPython port, importing the package loads only_component, and importing Reverb and Chorus loads just those two. The full suite is left to CI. I haven't run it on a board yet.