DwgObjectReader currently wraps _memoryStream with new Uint8Array(this._memoryStream) in the object-type/read path. Because _memoryStream is already a Uint8Array, this creates a full copy of the object stream each time.
On a 4.6MB AC1032 DWG, this made DwgReader.readFromStream() fail to complete after 180s and spend most sampled time in allocation/GC. Reusing the existing _memoryStream view made the same file parse in ~2.6s.
Measured locally:
readFileHeader: ~8ms
readHeader: ~5ms
readSummaryInfo: ~4ms
readPreview: ~2ms
read(): timed out after 180s before patch
read(): ~2661ms after patch
The fix is to pass this._memoryStream directly into DwgStreamReaderBase.getStreamHandler(...) instead of allocating a new Uint8Array copy for each reader.
I opened a PR with that change.
DwgObjectReadercurrently wraps_memoryStreamwithnew Uint8Array(this._memoryStream)in the object-type/read path. Because_memoryStreamis already aUint8Array, this creates a full copy of the object stream each time.On a 4.6MB AC1032 DWG, this made
DwgReader.readFromStream()fail to complete after 180s and spend most sampled time in allocation/GC. Reusing the existing_memoryStreamview made the same file parse in ~2.6s.Measured locally:
The fix is to pass
this._memoryStreamdirectly intoDwgStreamReaderBase.getStreamHandler(...)instead of allocating a newUint8Arraycopy for each reader.I opened a PR with that change.