From 6e4f5dc575a8631909bc10605a4b081d36353946 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 8 Apr 2025 11:05:13 +0200 Subject: [PATCH 1/5] add emojis for visualization --- scripts/ci_run_benchmark.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index 8f462c78..b5a58603 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -34,13 +34,13 @@ fi pushd "$CANISTER_PATH" canbench --less-verbose > $CANBENCH_OUTPUT if grep -q "(regress\|(improved by \|(new)" "$CANBENCH_OUTPUT"; then - UPDATED_MSG="**\`$CANBENCH_RESULTS_FILE\` is not up to date ❌** + UPDATED_MSG="**❌ \`$CANBENCH_RESULTS_FILE\` is not up to date** If the performance change is expected, run \`canbench --persist\` to save the updated benchmark results."; # canbench results file not up to date. Fail the job. echo "EXIT_STATUS=1" >> "$GITHUB_ENV" else - UPDATED_MSG="**\`$CANBENCH_RESULTS_FILE\` is up to date ✅**"; + UPDATED_MSG="**✅ \`$CANBENCH_RESULTS_FILE\` is up to date**"; # canbench results file is up to date. The job succeeds. echo "EXIT_STATUS=0" >> "$GITHUB_ENV" @@ -60,26 +60,27 @@ if [ -f "$MAIN_BRANCH_RESULTS_FILE" ]; then canbench --less-verbose > "$CANBENCH_OUTPUT" popd - if grep -q "(regress\|(improved by" "${CANBENCH_OUTPUT}"; then - echo "**Significant performance change detected! ⚠️** - " >> "$COMMENT_MESSAGE_PATH" - else - echo "**No significant performance changes detected ✅** - " >> "$COMMENT_MESSAGE_PATH" - fi + # Add emojis for visualization (as of December 2024, Github does not support colored text) + awk ' + /\(improved / { print $0, "🟢"; next } + /\(regressed / { print $0, "🔴"; next } + /\(new\)/ { print $0, "🟡"; next } + { print } + ' "$CANBENCH_OUTPUT" > "${CANBENCH_OUTPUT}.tmp" && mv "${CANBENCH_OUTPUT}.tmp" "$CANBENCH_OUTPUT" + + # Add a top-level summary of detected performance changes + MESSAGE="" + grep -q "(improved " "${CANBENCH_OUTPUT}" && MESSAGE+="**🟢 Performance improvements detected! 🎉**\n" + grep -q "(regressed " "${CANBENCH_OUTPUT}" && MESSAGE+="**🔴 Performance regressions detected! 😱**\n" + echo -e "${MESSAGE:-**ℹ️ No significant performance changes detected 👍**}" >> "$COMMENT_MESSAGE_PATH" fi -# Add emojis for visualization (as of December 2024, Github does not support colored text) -FORMATTED_CANBENCH_OUTPUT=$(cat "$CANBENCH_OUTPUT" \ - | sed -E 's/.*improved.*/\0 🟢/g' \ - | sed -E 's/.*regress.*/\0 🔴/g') - ## Add the output of canbench to the file. { echo "$UPDATED_MSG" echo "" echo "\`\`\`" - echo "$FORMATTED_CANBENCH_OUTPUT" + echo "$CANBENCH_OUTPUT" echo "\`\`\`" } >> "$COMMENT_MESSAGE_PATH" From 71893b11c888e8a17ba5778adbc79715b5f15639 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 8 Apr 2025 11:16:18 +0200 Subject: [PATCH 2/5] add commit hash & time --- scripts/ci_run_benchmark.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index b5a58603..9ff89908 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -47,8 +47,12 @@ else fi popd +# Get the latest commit hash +commit_hash=$(git rev-parse HEAD) +time=$(date -u +"%Y-%m-%d %H:%M:%S UTC") -echo "# \`canbench\` 🏋 (dir: $CANISTER_PATH)" > "$COMMENT_MESSAGE_PATH" +# Print output with correct formatting +echo "# \`canbench\` 🏋 (dir: $CANISTER_PATH) $commit_hash $time" > "$COMMENT_MESSAGE_PATH" # Detect if there are performance changes relative to the main branch. if [ -f "$MAIN_BRANCH_RESULTS_FILE" ]; then From 50df5079f47f5d7bedb28be38afc9fa99789d7cd Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 8 Apr 2025 11:20:08 +0200 Subject: [PATCH 3/5] fix report --- scripts/ci_run_benchmark.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_run_benchmark.sh b/scripts/ci_run_benchmark.sh index 9ff89908..4e1c74cd 100644 --- a/scripts/ci_run_benchmark.sh +++ b/scripts/ci_run_benchmark.sh @@ -84,7 +84,7 @@ fi echo "$UPDATED_MSG" echo "" echo "\`\`\`" - echo "$CANBENCH_OUTPUT" + cat "$CANBENCH_OUTPUT" echo "\`\`\`" } >> "$COMMENT_MESSAGE_PATH" From 429376c457d3aa5856315c8189c94f3c4517bc53 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 8 Apr 2025 11:22:08 +0200 Subject: [PATCH 4/5] test regression --- src/btreemap.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index 1ccb2700..b9b0011b 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -524,7 +524,12 @@ where /// Returns true if the key exists. pub fn contains_key(&self, key: &K) -> bool { // An empty closure returns Some(()) if the key is found. - self.root_addr != NULL && self.traverse(self.root_addr, key, |_, _| ()).is_some() + self.root_addr != NULL + && self + .traverse(self.root_addr, key, |node, idx| { + node.into_entry(idx, self.memory()).1 // TODO: remove debug code. + }) + .is_some() } /// Recursively traverses from `node_addr`, invoking `f` if `key` is found. Stops at a leaf if not. From b904981ae497a8edcff33b6a68e1c3cd939726e3 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 8 Apr 2025 11:26:22 +0200 Subject: [PATCH 5/5] revert regression --- src/btreemap.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index b9b0011b..1ccb2700 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -524,12 +524,7 @@ where /// Returns true if the key exists. pub fn contains_key(&self, key: &K) -> bool { // An empty closure returns Some(()) if the key is found. - self.root_addr != NULL - && self - .traverse(self.root_addr, key, |node, idx| { - node.into_entry(idx, self.memory()).1 // TODO: remove debug code. - }) - .is_some() + self.root_addr != NULL && self.traverse(self.root_addr, key, |_, _| ()).is_some() } /// Recursively traverses from `node_addr`, invoking `f` if `key` is found. Stops at a leaf if not.