Repository navigation
Conversation
Make HashSink extend ByteConversionSink instead of implementing Sink<List<int>> and wrapping it with ByteConversionSink.from(...) in each Hash.startChunkedConversion implementation. Also override HashSink.addSlice to pass (data, start, end) directly to _addData without allocating a sublist copy.
…HashSink Allocate a single Uint32List(chunkSizeInWords) buffer in HashSink and create _chunk (asUint8List) and non-nullable _byteDataView (asByteData) as views over the same ByteBuffer. Once a chunk is filled, each 32-bit word j is read from _byteDataView at [j * 4 .. j * 4 + 3] and written in-place to _chunk32[j] at the same 4-byte offset before calling updateHash(_chunk32), after which chunkNextIndex is reset to 0.
…an.host Because _chunk and _chunk32 are views over the same ByteBuffer and Uint32List accesses words in Endian.host byte order, _chunk32[j] already holds _byteDataView.getUint32(j * 4, _endian) whenever _endian == Endian.host.
Pass constant shift amounts directly to round(e, f, i, s) in each of the four 16-step loops so rotl32 compiles to immediate 32-bit rotates, and replace % 16 with & 15.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimize
HashSinkand_MD5Sink.updateHashto reduce allocations and improve MD5 throughput (~1.4x in AOT, ~1.25x in JIT):4 commits:
Make
HashSinkextendByteConversionSinkdirectly:Eliminates the
_ByteAdapterSinkwrapper allocation and virtualSink<List<int>>dispatch instartChunkedConversion, and overridesaddSliceto avoidsublistallocations.Share buffer between
_chunkand_chunk32inHashSink:Uses a single
Uint32List(chunkSizeInWords)buffer shared by_chunkand_byteDataView, and skips the 16-wordgetUint32copy loop per block when_endian == Endian.host.Pad in-place in
HashSink._finalizeAndProcessDataand usesetUint64:Writes the
0x80marker, zero padding, and 64-bit bit-length directly into_chunkwithout allocating a temporarypaddingUint8List, and uses_byteDataView.setUint64when!const bool.fromEnvironment('dart.library.js_interop').Unroll
_MD5Sink.updateHashrounds by 4:Replaces the nested
round(int i)closure and_shiftAmountslookup table with static@pragma('vm:prefer-inline')round helpers (_ff,_gg,_hh,_ii) and constant shift amounts.