-
Notifications
You must be signed in to change notification settings - Fork 54
Refactor AsyncFileResponse: remove String _path #235
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
base: main
Are you sure you want to change the base?
Refactor AsyncFileResponse: remove String _path #235
Conversation
This refactor eliminates the private String _path member from the AsyncFileResponse class, replacing its functionality with a fixed-size char gzPath[MAX_PATH] buffer insife of function. The use of Arduino's dynamic String class has known drawbacks in memory-constrained or real-time systems, particularly due to heap fragmentation and unpredictable allocation behavior. By switching to a statically allocated C-style buffer, the implementation now benefits from improved memory determinism, reduced fragmentation risk, and overall lower memory overhead. In addition to reducing memory fragmentation and improving stability in embedded environments, this change also yields better execution speed. This change maintains behavioral equivalence.
#mathieucarbou and #me-no-dev |
Thank you very much for indicating compatibility with other devices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the AsyncFileResponse class to eliminate the private String _path member variable and replaces it with local variables to improve memory management in embedded environments. The change aims to reduce heap fragmentation and improve performance by avoiding dynamic String allocations.
- Removes the private String _path member from AsyncFileResponse class
- Replaces _path usage with local String variable gzPath in constructor for compressed file handling
- Maintains the same functionality while improving memory determinism
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/WebResponseImpl.h | Removes the private String _path member declaration from AsyncFileResponse class |
src/WebResponses.cpp | Updates constructors to use local gzPath variable instead of storing path in member variable |
Co-authored-by: Copilot <[email protected]>
@me-no-dev : can you please have a look again ? PR looks good to me. Thanks! |
This refactor eliminates the private String _path member from the AsyncFileResponse class, replacing its functionality with a fixed-size char gzPath[MAX_PATH] buffer insife of function.
The use of Arduino's dynamic String class has known drawbacks in memory-constrained or real-time systems, particularly due to heap fragmentation and unpredictable allocation behavior. By switching to a statically allocated C-style buffer, the implementation now benefits from improved memory determinism, reduced fragmentation risk, and overall lower memory overhead. In addition to reducing memory fragmentation and improving stability in embedded environments, this change also yields better execution speed. This change maintains behavioral equivalence.