Skip to content

Commit

Permalink
feat: retrieve v8 flags from @codspeed/core introspection mechanism
Browse files Browse the repository at this point in the history
Co-authored-by: @adriencaccia
  • Loading branch information
art049 committed Jun 27, 2023
1 parent f5d6dfd commit f3a7b75
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
47 changes: 21 additions & 26 deletions dist/bin/node
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -eo pipefail
# benchmarks more predictable.
# Depending on the version of node, some flags may be deprecated.

# to avoid setting the variable for the children processes, unset it before running the node command
unset __CODSPEED_NODE_CORE_INTROSPECTION_PATH__

# Retrieve the original path by removing the folder containing CodSpeedHQ/action from the path.
ORIGINAL_PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "CodSpeedHQ/action" | tr "\n" ":")
# Check if node is in the original path.
Expand All @@ -15,34 +18,26 @@ fi
# Save the real node path.
REAL_NODE_PATH=$(env PATH="$ORIGINAL_PATH" which node)

V8_FLAGS=(
"--hash-seed=1"
"--random-seed=1"
"--no-opt"
"--predictable"
"--predictable-gc-schedule"
)

# get node major version, using bash regex
NODE_MAJOR_VERSION=$($REAL_NODE_PATH --version | sed -E 's/^v([0-9]+)\..*$/\1/')

# add flags deprecated in node 18 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 18 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-randomize-hashes"
)
fi
# add flags deprecated in node 20 in older versions
if [ "$NODE_MAJOR_VERSION" -lt 20 ]; then
V8_FLAGS=(
"${V8_FLAGS[@]}"
"--no-scavenge-task"
)
# Generate a random file in /tmp to store introspection data
INTROSPECTION_FILE=$(mktemp)
echo "::debug::Introspection file: $INTROSPECTION_FILE"

# Temporarily disable 'set -e' for the command and capture its exit code.
echo ::debug::Introspection trigger: env __CODSPEED_NODE_CORE_INTROSPECTION_PATH__="$INTROSPECTION_FILE" $REAL_NODE_PATH "$@"
env __CODSPEED_NODE_CORE_INTROSPECTION_PATH__="$INTROSPECTION_FILE" $REAL_NODE_PATH "$@"

# If the introspection file is empty, it means that the introspection didn't happen
if [ ! -s "$INTROSPECTION_FILE" ]; then
echo "::debug::No introspection detected (no introspection file found)"
exit 0 # the exit code is 0 since otherwise the execution would have been stopped by 'set -e'
fi

# Retrieve the V8 flags from the introspection file
V8_FLAGS=$(jq -r '.flags | join(" ")' "$INTROSPECTION_FILE")
echo "::debug::V8 flags harvested from introspection: $V8_FLAGS"

echo "::debug::Running the CodSpeed node script, the node command that will be run:"
echo "::debug::$REAL_NODE_PATH" "${V8_FLAGS[@]}" "$@"
echo "::debug::$REAL_NODE_PATH" $V8_FLAGS "$@"

# Call the real "node" command with any arguments passed to this script.
$REAL_NODE_PATH "${V8_FLAGS[@]}" "$@"
$REAL_NODE_PATH $V8_FLAGS "$@"
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ const run = async (inputs: ActionInputs): Promise<{profileFolder: string}> => {
PATH: `${customBinPath}:${process.env.PATH}`,
PYTHONMALLOC: "malloc",
PYTHONHASHSEED: "0",
/**
* @deprecated this should not be used to add new flags and
* the getV8Flags from codspeed-node should be preferred
* (available from 1.2.0)
*/
CODSPEED_V8_FLAGS: [
"--hash-seed=1",
"--random-seed=1",
"--no-randomize-hashes",
"--no-scavenge-task",
"--no-opt ",
"--predictable ",
"--predictable-gc-schedule",
].join(" "),
ARCH: arch,
CODSPEED_ENV: "github",
},
Expand Down

0 comments on commit f3a7b75

Please sign in to comment.