Open pbcornell opened 5 years ago
The lowlevelbinarywriter could easily reset its writeable object but it wouldn't save much as its mostly a wrapper with some byte generation methods. The writeable inside could have a clear() method instead that would instantiate a new buffer / clean state. Its not clear to me how much of a perf improvement it would add but I could see it cutting down on garbage collection quite a bit in a long running application.
LowLevelBinaryWriter is currently written to be used once, then thrown away. For example: https://github.com/amzn/ion-js/blob/81d58d3e9f83cb741ded5940d2c8abf6d8cca979/src/IonBinaryWriter.ts#L121
There are likely efficiencies to be gained by allowing an instance of this object to be reused instead of discarded.