In torch::save() avoid zip compressing small header records. (#28180)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28180
ScriptModuleSerializer::writeCode() is the only place during torch::save()
serialization where we attempt to zip compress records.
This change avoids compressing these string records if they are
sufficiently small - e.g. in the example I looked at:
- the strings were 123 and 28 bytes, respectively.
- the cost in the compression routines was 16.5% of the torch::save() cost.
(we're building a huffman table for a 28 byte string).
We'd save time and not significantly affect the space if we add these
1-line conditional compressions, rather than making it unconditional.
ghstack-source-id: 92104517
Test Plan:
Benchmark: experimental/jeremyl/c2:SerializationBench
Correctness: normal buck mode/dev-nosan caffe2/test/...
Differential Revision: D17967995
fbshipit-source-id: 7ff934388533645dc987e105c814ffe6324f4596