Refactor EventStream::sendFrame to use reusable filepath member#4616
Draft
Refactor EventStream::sendFrame to use reusable filepath member#4616
Conversation
Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor filepath handling in EventStream::sendFrame
Refactor EventStream::sendFrame to use reusable filepath member
Feb 11, 2026
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.
Eliminates per-frame heap allocations in
EventStream::sendFrameby replacing the localstd::string filepathvariable with a reusable memberreuse_filepath_.Changes
src/zm_eventstream.h: Addedstd::string reuse_filepath_member to EventStream classsrc/zm_eventstream.cpp:filepathvariable withreuse_filepath_.clear()at method entry.c_str(),.empty()calls) to use member variablePerformance Impact
After the first frame, the string's internal buffer is reused across subsequent
sendFrame()calls, avoiding repeated allocations fromstringtf()on hot path.Before:
std::string filepath; // new allocation each sendFrame call filepath = stringtf(...);After:
reuse_filepath_.clear(); // reuses existing buffer capacity reuse_filepath_ = stringtf(...);Original prompt
Problem Statement
Refactor the filepath handling in EventStream::sendFrame to use a pre-allocated reusable
std::stringmember instead of the C-stylechar[PATH_MAX]buffer withsnprintf()introduced in PR #4609.Context
PR #4609 (commit c8d5ea3) optimized EventStream::sendFrame by replacing
stringtf()calls withsnprintf()into a stack-allocatedchar[PATH_MAX]buffer wrapped instd::string_view. While this eliminated heap allocations, it uses C-style string handling.This PR proposes a more idiomatic C++ approach that achieves the same performance benefits while maintaining type safety.
Proposed Changes
1. Add reusable string member to EventStream class
File:
src/zm_eventstream.hIn the private section of the
EventStreamclass (around line 127-130), modify:2. Refactor sendFrame method to use reuse_filepath_
File:
src/zm_eventstream.cppIn the
EventStream::sendFramemethod (starting around line 844), replace the current implementation that useschar filepath_buf[PATH_MAX]andstd::string_view filepathwith the reusable string approach:Current code (from PR #4609):
Replace with:
3. Update all uses of filepath in sendFrame
Throughout the rest of the
sendFramemethod, replace references tofilepath_bufandfilepathwithreuse_filepath_:Around line 877-882 (STREAM_MPEG path):
Around line 901-908 (send_raw path):
Around line 910-913 (image loading path):