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

Controllable memory allocation #45

Open
JensOgorek opened this issue Jan 8, 2025 · 2 comments
Open

Controllable memory allocation #45

JensOgorek opened this issue Jan 8, 2025 · 2 comments

Comments

@JensOgorek
Copy link

JensOgorek commented Jan 8, 2025

Hello,
we use owl on our ESP32 in our firmware zauberzeug/lizard. Occasionally, the ESP32 devices would hang during usage, especially when running long startup scripts.

After some digging, we found the function owl_default_tokenizer_advance attempts to allocate 40 KB of RAM for every line processed. On an ESP32, this can quickly lead to problems due to limited memory availability.
In our version of owl, we reduced the allocation size from 4096 to 256, which now only consumes 2.5 KB of RAM. For example, in a longer call, we only process up to 24 tokens at a time, which works well with this adjustment.

Do you have an idea for making tokenizer_advance more scalable? One suggestion we had was to introduce a configurable parameter in owl_tree_options to allow users to set the token count dynamically, with a default of 4096.

Optional Enhancement:
It could be beneficial to introduce a dedicated error state for cases where allocation fails, as the current error provided by owl does not clearly indicate that the issue is related to memory allocation. This would make diagnosing such problems more straightforward and user-friendly.

ianh added a commit that referenced this issue Jan 8, 2025
This lets library users make the tradeoff between memory use and throughput.

See #45.
ianh added a commit that referenced this issue Jan 8, 2025
@ianh
Copy link
Owner

ianh commented Jan 8, 2025

Sounds good -- with dba6335, you can use #define OWL_TOKEN_RUN_LENGTH before including the parser implementation to override the default. ae33e64 should properly report when the relevant allocation fails, though there are other allocations which don't have proper error handling at the moment.

@JensOgorek
Copy link
Author

That works great, besides the #define OWL_TOKEN_RUN_LENGTH getting ignored from main.cpp, if I add it before #include parser.h.
But, adding the #define to parser.c or add_compile_definitions(OWL_TOKEN_RUN_LENGTH=256) in CMakeLists works.

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

No branches or pull requests

2 participants