greymd / teip

Masking tape to help commands "do one thing well"
MIT License
569 stars 19 forks source link

-e option allocates memory aggressively #35

Open greymd opened 2 years ago

greymd commented 2 years ago

See https://github.com/greymd/teip/wiki/Memory-Usage-Benchmark

-e requires approx 3 times as much memory as the standard input. It can be reduced more.

Let me note my brief idea. One of the reasons why it allocates large mount of memory is standard input is taken "hard copy" in _tee_thread. https://github.com/greymd/teip/blob/v2.0.0/src/main.rs#L294-L349

Instead of hard copy of text, the text can be possessed in a linked list or a ring buffer. If so, _tee_thread will not need to pass text through channel, instead, pass the index numbers of buffer.

Then, Main thread and _ex_thread may have to refer to the shared mutex object which indicates the latest index. All the data stored on the indexes smaller than the latest one would be released then.

greymd commented 1 year ago

Put help wante label. Currently, I do not have enough resources to address this issue. Any PRs are welcome.