Commit a4409f3
perf: reduce per-frame overhead in EventStream::sendFrame
Three changes to the JPEG streaming hot path:
1. Reuse Image buffer for JPEG decode: add Image member reuse_image_
to EventStream. On the JPEG path (SaveJPEGs & 1), call ReadJpeg()
into the member instead of new/delete Image each frame. ReadJpeg's
internal WriteBuffer() reuses the pixel allocation when dimensions
match (every frame in a given event). Eliminates ~2 MB malloc+free
per streamed frame. The FFmpeg path (MP4-only events) still uses
new/delete since its initialization is more complex and it's the
uncommon case.
2. Replace stat() with access() for file existence checks. The stat()
filled a struct stat that was never read — send_file() does its own
fstat() for Content-Length. access(path, R_OK) is a lighter syscall
that skips the 144-byte struct fill.
3. Replace stringtf() with snprintf() into a stack char[PATH_MAX].
stringtf() does two heap allocations per call (unique_ptr<char[]>
for vsnprintf + std::string for return). File paths are well within
PATH_MAX. This eliminates 2-6 heap alloc/free cycles per frame
depending on the analysis fallback path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent df88c73 commit a4409f3
2 files changed
+20
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
851 | 853 | | |
852 | 854 | | |
853 | 855 | | |
854 | | - | |
855 | | - | |
| 856 | + | |
856 | 857 | | |
857 | 858 | | |
858 | 859 | | |
859 | 860 | | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
867 | 868 | | |
868 | 869 | | |
869 | 870 | | |
870 | | - | |
| 871 | + | |
871 | 872 | | |
872 | 873 | | |
873 | 874 | | |
874 | 875 | | |
875 | 876 | | |
876 | 877 | | |
877 | | - | |
| 878 | + | |
878 | 879 | | |
879 | 880 | | |
880 | 881 | | |
| |||
889 | 890 | | |
890 | 891 | | |
891 | 892 | | |
892 | | - | |
| 893 | + | |
893 | 894 | | |
894 | 895 | | |
895 | 896 | | |
896 | | - | |
897 | | - | |
| 897 | + | |
| 898 | + | |
898 | 899 | | |
899 | 900 | | |
900 | 901 | | |
901 | 902 | | |
902 | 903 | | |
903 | | - | |
904 | | - | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
905 | 907 | | |
906 | 908 | | |
907 | 909 | | |
| |||
977 | 979 | | |
978 | 980 | | |
979 | 981 | | |
980 | | - | |
| 982 | + | |
981 | 983 | | |
982 | 984 | | |
983 | 985 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
0 commit comments