Files
Takeshi Watanabe c12d3a8b3e Fix LoadProtoFromPath's byte-at-a-time file read (#8345)
std::string data{istreambuf_iterator{stream}, istreambuf_iterator{}}
copies a file one character at a time (each increment pays a stream
buffer-boundary check), instead of one bulk read. For small models this
is noise; for a large one it is seconds -- measured costing the bulk of
a ~16s gap between onnx-optimizer's path-based loadModel/saveModel and
the equivalent Python-side onnx.load on an 833MB model
(https://github.com/onnxsim/onnxsim/issues/633's investigation into
loadModel's path-based entry points, used by its own SimplifyPath fast
path).

Sizes the file up front via std::filesystem::file_size and does a single
read() into a pre-sized string; falls back to the old iterator-based
read if the size can't be determined (e.g. a pipe). Correctness is
checked via gcount() rather than the stream's good()/eof() flags, since
a read() that consumes exactly to EOF can set eofbit on a stream
implementation even though every requested byte was read.

(cherry picked from commit 4784075aa7d40a771eaf70c12d0eeaee3d5d3a17)



### Motivation and Context

Fixes #

Signed-off-by: take-cheeze <takechi101010@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-08-21 16:22:41 +08:00
..
2024-04-16 04:45:17 +00:00
2026-05-11 15:04:46 +02:00
2025-11-06 14:31:33 -08:00
2026-06-06 07:55:50 -07:00
2026-05-11 15:04:46 +02:00
2026-02-05 08:33:09 -05:00
2026-05-11 15:04:46 +02:00