Skip to content

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 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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mathieucarbou
Copy link
Member

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

@mathieucarbou mathieucarbou removed the request for review from me-no-dev August 4, 2025 13:51
@mathieucarbou mathieucarbou merged commit b658d62 into ESP32Async:main Aug 4, 2025
32 checks passed
@JosePineiro JosePineiro deleted the refactor/remove-path-from-asyncfileresponse branch August 19, 2025 18:59
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