amazon-ion / ion-js

A JavaScript implementation of Amazon Ion.
http://amzn.github.io/ion-docs/
Apache License 2.0
353 stars 48 forks source link

consider making LowLevelBinaryWriter reusable #306

Open pbcornell opened 5 years ago

pbcornell commented 5 years ago

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.

wesboyt commented 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.