From a38b430d95336d9fe03725d1b8c098386c352310 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Tue, 2 May 2023 17:26:11 -0700 Subject: [PATCH 01/15] perf from moc artifact --- .github/workflows/perf.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index 11d49145..cce19d80 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -14,7 +14,7 @@ jobs: DFX_VERSION: 0.13.1 VESSEL_VERSION: v0.6.4 IC_REPL_VERSION: 0.3.18 - MOC_VERSION: 0.8.7 + MOC_ARTIFACT: 676558399 steps: - uses: actions/checkout@v3 - name: Checkout out gh-pages report @@ -56,9 +56,9 @@ jobs: cp ./vessel-linux64 /usr/local/bin/vessel chmod a+x /usr/local/bin/vessel dfx cache install - cd $(dfx cache show) - wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-linux64-$MOC_VERSION.tar.gz - tar zxvf motoko-linux64-$MOC_VERSION.tar.gz + wget https://nightly.link/dfinity/motoko/actions/artifacts/$MOC_ARTIFACT.zip + unzip $MOC_ARTIFACT.zip + cp bin/moc $(dfx cache show) - name: Start dfx run: | dfx start --background From 510bad26c25b1220f742ac7511719b9e097cb4c9 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Tue, 2 May 2023 17:30:37 -0700 Subject: [PATCH 02/15] fix --- .github/workflows/perf.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index cce19d80..904e2066 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -58,7 +58,8 @@ jobs: dfx cache install wget https://nightly.link/dfinity/motoko/actions/artifacts/$MOC_ARTIFACT.zip unzip $MOC_ARTIFACT.zip - cp bin/moc $(dfx cache show) + chmod a+x bin/moc + cp -rf bin/moc $(dfx cache show) - name: Start dfx run: | dfx start --background From 48d0853439606946541f24b511655a65fddae4e4 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Wed, 3 May 2023 09:56:11 -0700 Subject: [PATCH 03/15] trigger CI From 71cfcdea345c20db5b37b5ffe7e04226a433f1eb Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Tue, 13 Feb 2024 19:42:09 +0000 Subject: [PATCH 04/15] Update .github/workflows/perf.yml --- .github/workflows/perf.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index dafd32d5..f42fd4f5 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -71,9 +71,6 @@ jobs: cp -rf bin/moc $(dfx cache show) wget https://github.com/dfinity/ic-wasm/releases/download/$IC_WASM_VERSION/ic-wasm-linux64 cp ./ic-wasm-linux64 /usr/local/bin/ic-wasm - cd $(dfx cache show) - wget https://github.com/dfinity/motoko/releases/download/$MOC_VERSION/motoko-Darwin-x86_64-$MOC_VERSION.tar.gz - tar zxvf motoko-Darwin-x86_64-$MOC_VERSION.tar.gz wget https://github.com/dfinity/ic-wasm/releases/download/$IC_WASM_VERSION/ic-wasm-macos cp ./ic-wasm-macos /usr/local/bin/ic-wasm chmod a+x /usr/local/bin/ic-wasm From 81ed4c774bbc352e04952dad3a14cc244c052a76 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:55:07 -0800 Subject: [PATCH 05/15] retrigger CI --- .github/workflows/perf.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index f42fd4f5..e678aebf 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -69,8 +69,6 @@ jobs: unzip $MOC_ARTIFACT.zip chmod a+x bin/moc cp -rf bin/moc $(dfx cache show) - wget https://github.com/dfinity/ic-wasm/releases/download/$IC_WASM_VERSION/ic-wasm-linux64 - cp ./ic-wasm-linux64 /usr/local/bin/ic-wasm wget https://github.com/dfinity/ic-wasm/releases/download/$IC_WASM_VERSION/ic-wasm-macos cp ./ic-wasm-macos /usr/local/bin/ic-wasm chmod a+x /usr/local/bin/ic-wasm From 1b763c41fd5d27398e05262985a3cf21c7259330 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Wed, 14 Feb 2024 14:26:11 +0000 Subject: [PATCH 06/15] use better hash function --- collections/motoko/src/ZhenyaHashmap.mo | 6 +++--- collections/motoko/src/hashmap.mo | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 7d2d20e9..4fd82303 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -5,11 +5,11 @@ import Iter "mo:base/Iter"; import Option "mo:base/Option"; import Random "random"; import Profiling "../../../utils/motoko/Profiling"; - +import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - - func f_hash(x : Nat64) : Nat32 = Hash.hash(Nat64.toNat x); + + func f_hash(x : Nat64) : Nat32 = Prim.nat64ToNat32(x & 0xffffffff); let hash : HashMap.HashUtils = (f_hash, Nat64.equal); stable var map = HashMap.new(); let rand = Random.new(null, 42); diff --git a/collections/motoko/src/hashmap.mo b/collections/motoko/src/hashmap.mo index 92b70983..f8ae4fc1 100644 --- a/collections/motoko/src/hashmap.mo +++ b/collections/motoko/src/hashmap.mo @@ -9,7 +9,7 @@ import Profiling "../../../utils/motoko/Profiling"; actor { stable let profiling = Profiling.init(); - + func hash(x: Nat64) : Nat32 = Hash.hash(Nat64.toNat x); var map = HashMap.HashMap(0, Nat64.equal, hash); stable var stableMap: [(Nat64, Nat64)] = []; From 77a920eac12db696d2893778b75cf83a44df44a3 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Wed, 14 Feb 2024 16:44:12 +0000 Subject: [PATCH 07/15] avoid boxing (changes baseline) --- collections/motoko/src/ZhenyaHashmap.mo | 2 +- collections/motoko/src/random.mo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 4fd82303..378bab58 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,7 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - func f_hash(x : Nat64) : Nat32 = Prim.nat64ToNat32(x & 0xffffffff); + func f_hash(x : Nat64) : Nat32 = Hash.hash(Nat64.toNat x); let hash : HashMap.HashUtils = (f_hash, Nat64.equal); stable var map = HashMap.new(); let rand = Random.new(null, 42); diff --git a/collections/motoko/src/random.mo b/collections/motoko/src/random.mo index 4a4222fb..b966d66e 100644 --- a/collections/motoko/src/random.mo +++ b/collections/motoko/src/random.mo @@ -4,7 +4,7 @@ import Prim "mo:⛔"; module { public class new(size: ?Nat32, seed: Nat64) { - let modulus : Nat64 = 0x7fffffff; + let modulus : Nat64 = 0xfffffff; //0x7fffffff; var state : Nat64 = seed; var ind : Nat32 = 0; From d54690b0520b462e3067470080cc78cace355d1f Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Wed, 14 Feb 2024 18:48:59 +0000 Subject: [PATCH 08/15] restore RNG; return 28 high bits instead to avoid boxing and duplication --- collections/motoko/src/random.mo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collections/motoko/src/random.mo b/collections/motoko/src/random.mo index b966d66e..5e8ea58c 100644 --- a/collections/motoko/src/random.mo +++ b/collections/motoko/src/random.mo @@ -4,7 +4,7 @@ import Prim "mo:⛔"; module { public class new(size: ?Nat32, seed: Nat64) { - let modulus : Nat64 = 0xfffffff; //0x7fffffff; + let modulus : Nat64 = 0x7fffffff; var state : Nat64 = seed; var ind : Nat32 = 0; @@ -19,7 +19,7 @@ module { }; }; state := state * 48271 % modulus; - ?state; + ?(state>>4); }; }; public func get_memory(): (Nat,Nat,Nat) { From bc41fe4df4047f747c8f53e1ca0b960598511487 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Wed, 14 Feb 2024 22:30:16 +0000 Subject: [PATCH 09/15] insert spaces --- collections/motoko/src/random.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collections/motoko/src/random.mo b/collections/motoko/src/random.mo index 5e8ea58c..2b67db8c 100644 --- a/collections/motoko/src/random.mo +++ b/collections/motoko/src/random.mo @@ -19,7 +19,7 @@ module { }; }; state := state * 48271 % modulus; - ?(state>>4); + ?(state >> 4); }; }; public func get_memory(): (Nat,Nat,Nat) { From 9431cae1eb82ec882e2b1579ca8f300d7b645264 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 10:45:48 +0000 Subject: [PATCH 10/15] use better hash --- collections/motoko/src/ZhenyaHashmap.mo | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 378bab58..3b635290 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,8 +9,7 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - func f_hash(x : Nat64) : Nat32 = Hash.hash(Nat64.toNat x); - let hash : HashMap.HashUtils = (f_hash, Nat64.equal); + let hash : HashMap.HashUtils = Map.n64hash; stable var map = HashMap.new(); let rand = Random.new(null, 42); From d15162e878c4b1414107e3a62a4cdcb1e3552a66 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 12:14:17 +0000 Subject: [PATCH 11/15] Apply suggestions from code review --- collections/motoko/src/ZhenyaHashmap.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 3b635290..19b7d8df 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,7 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - let hash : HashMap.HashUtils = Map.n64hash; + let hash : HashMap.HashUtils = HashMap.n64hash; stable var map = HashMap.new(); let rand = Random.new(null, 42); From f6b671de6a08340c454449185655284f8078a53d Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 15:18:14 +0000 Subject: [PATCH 12/15] simplify hash to just use low 28 bits --- collections/motoko/src/ZhenyaHashmap.mo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 19b7d8df..4547e1c0 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,12 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - let hash : HashMap.HashUtils = HashMap.n64hash; + let public func hashNat64(key: Nat64): Nat32 { + Prim.nat64ToNat32(key & 0x0fff_ffff); + }; + + let hash : HashMap.HashUtils = (hashNat64, func (x,y) = x == y); + stable var map = HashMap.new(); let rand = Random.new(null, 42); From ae72433b89f768466e6b9680b2b3d5bf7357aaec Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 16:16:11 +0000 Subject: [PATCH 13/15] Apply suggestions from code review --- collections/motoko/src/ZhenyaHashmap.mo | 2 +- collections/motoko/src/hashmap.mo | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 4547e1c0..f74a84cb 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,7 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - let public func hashNat64(key: Nat64): Nat32 { + hashNat64(key: Nat64): Nat32 { Prim.nat64ToNat32(key & 0x0fff_ffff); }; diff --git a/collections/motoko/src/hashmap.mo b/collections/motoko/src/hashmap.mo index f8ae4fc1..ea8f1b3e 100644 --- a/collections/motoko/src/hashmap.mo +++ b/collections/motoko/src/hashmap.mo @@ -9,7 +9,6 @@ import Profiling "../../../utils/motoko/Profiling"; actor { stable let profiling = Profiling.init(); - func hash(x: Nat64) : Nat32 = Hash.hash(Nat64.toNat x); var map = HashMap.HashMap(0, Nat64.equal, hash); stable var stableMap: [(Nat64, Nat64)] = []; From e52f850d40fd7fa855d73025da42126dc99a8dcc Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 17:16:41 +0000 Subject: [PATCH 14/15] Update collections/motoko/src/ZhenyaHashmap.mo --- collections/motoko/src/ZhenyaHashmap.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index f74a84cb..2f9f23b9 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,7 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - hashNat64(key: Nat64): Nat32 { + func hashNat64(key: Nat64): Nat32 { Prim.nat64ToNat32(key & 0x0fff_ffff); }; From 7b87f91a05b85e8d79757eb2eefd2a87057d1084 Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Sat, 17 Feb 2024 10:17:05 +0000 Subject: [PATCH 15/15] simplify hash to just use low 27 bits --- collections/motoko/src/ZhenyaHashmap.mo | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 4547e1c0..37a6a981 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,8 +9,9 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); + // avoid boxed hashes let public func hashNat64(key: Nat64): Nat32 { - Prim.nat64ToNat32(key & 0x0fff_ffff); + Prim.nat64ToNat32(key & 0x7ff_ffff); // Nat32 is 27-bit }; let hash : HashMap.HashUtils = (hashNat64, func (x,y) = x == y);