-
Notifications
You must be signed in to change notification settings - Fork 23
Speedup package:crypto (with a focus on md5) #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
An aot-compile, hashing a big file says ``` Difference at 95.0% confidence -140.4 +/- 35.1436 -11.2825% +/- 2.82414% (Student's t, pooled s = 24.0967) ```
PR HealthBreaking changes ✔️
Changelog Entry ❗
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with
Coverage
|
File | Coverage |
---|---|
pkgs/crypto/benchmark/benchmark.dart | 💔 Not covered |
pkgs/crypto/lib/src/hash_sink.dart | 💚 98 % ⬆️ 0 % |
pkgs/crypto/lib/src/md5.dart | 💚 100 % |
pkgs/crypto/tool/md5sum.dart | 💔 Not covered |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check
.
API leaks ✔️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
Package | Leaked API symbols |
---|
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files |
---|
no missing headers |
All source files should start with a license header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Feel free to ignore my style comments if it works and is faster, and you can't be bothered.
We can always improve more later.
} else if (arg == 'sha512256') { | ||
setFunction(sha512256, 'sha512/256'); | ||
} else { | ||
throw ArgumentError('Unknown argument: $arg'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe print an error on stderr
and exit. This is a command line usage mistake, not a Dart argument error.
print('Using hash function $message'); | ||
} | ||
|
||
for (var arg in args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you only need to look at args.first
. If there are two, either one is an error, or the second will find the function already set.
TL;DR
This makes it faster and use less ram.
Details
Tested on
out/ReleaseX64/wasm-opt
from a dart sdk build (167MB):JIT,
dart --deterministic
:JIT,
dart
:AOT,
dartaotruntime --deterministic
:AOT,
dartaotruntime
:Running the AOT snapshots through the "benchmarker" utility from dart front_end I get these results (with 25 runs of each version):
Running it through
/usr/bin/time -v
reports the "Maximum resident set size (kbytes)" going from around ~346k to ~176k (i.e. uses about half the ram).MD5 calculations is used internally in the analyzer, and patching this in, for an AOT compile of the analyzer we see changes like this (when run through the benchmarker with parameters like
--train-using pkg/front_end/lib/
in the dart sdk):