Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

JosePineiro
Copy link

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.

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 mathieucarbou marked this pull request as draft July 18, 2025 15:11
@JosePineiro
Copy link
Author

#mathieucarbou and #me-no-dev
Please, read #236 and give me an answer.
Thanks in advance.

@mathieucarbou mathieucarbou marked this pull request as ready for review July 24, 2025 09:51
Copy link

@Copilot Copilot AI left a 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

@mathieucarbou
Copy link
Member

@me-no-dev : can you please have a look again ? PR looks good to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants