Skip to content

Commit a6e4a1f

Browse files
authored
feat: Add --gc-frequency option to debug-build.sh (#1395)
1 parent d904b59 commit a6e4a1f

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

runtime/fastly/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ add_builtin(fastly::html_rewriter
6363

6464
add_compile_definitions(PUBLIC RUNTIME_VERSION=${RUNTIME_VERSION})
6565

66+
if(DEFINED FASTLY_GC_FREQUENCY)
67+
add_compile_definitions(PUBLIC FASTLY_GC_FREQUENCY=${FASTLY_GC_FREQUENCY})
68+
endif()
69+
6670
project(FastlyJS)

runtime/fastly/build-debug.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,37 @@ set -euo pipefail
44
set -x
55

66
cd "$(dirname "$0")" || exit 1
7+
8+
# Parse command line arguments
9+
KEEP_DEBUG_INFO=0
10+
GC_FREQUENCY=""
11+
12+
while [[ $# -gt 0 ]]; do
13+
case $1 in
14+
--keep-debug-info)
15+
KEEP_DEBUG_INFO=1
16+
shift
17+
;;
18+
--gc-frequency)
19+
if [[ -n "${2:-}" ]]; then
20+
GC_FREQUENCY="-DFASTLY_GC_FREQUENCY=$2"
21+
shift 2
22+
else
23+
echo "Error: --gc-frequency requires a value"
24+
exit 1
25+
fi
26+
;;
27+
*)
28+
echo "Unknown option: $1"
29+
exit 1
30+
;;
31+
esac
32+
done
33+
734
RUNTIME_VERSION=$(npm pkg get version --json --prefix=../../ | jq -r)
8-
HOST_API=$(realpath host-api) cmake -B build-debug -DCMAKE_BUILD_TYPE=Debug -DENABLE_BUILTIN_WEB_FETCH=0 -DENABLE_BUILTIN_WEB_FETCH_FETCH_EVENT=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DRUNTIME_VERSION="\"$RUNTIME_VERSION-debug\"" -DENABLE_JS_DEBUGGER=OFF
35+
HOST_API=$(realpath host-api) cmake -B build-debug -DCMAKE_BUILD_TYPE=Debug -DENABLE_BUILTIN_WEB_FETCH=0 -DENABLE_BUILTIN_WEB_FETCH_FETCH_EVENT=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DRUNTIME_VERSION="\"$RUNTIME_VERSION-debug\"" -DENABLE_JS_DEBUGGER=OFF "$GC_FREQUENCY"
936
cmake --build build-debug --parallel 10
10-
if [ "${1:-default}" != "--keep-debug-info" ]; then
37+
if [ "$KEEP_DEBUG_INFO" -eq 0 ]; then
1138
wasm-tools strip build-debug/starling-raw.wasm/starling-raw.wasm -d ".debug_(info|loc|ranges|abbrev|line|str)" -o ../../fastly.debug.wasm
1239
else
1340
cp build-debug/starling-raw.wasm/starling-raw.wasm ../../fastly.debug.wasm

runtime/fastly/handler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ api::Engine *ENGINE;
1919

2020
// Install corresponds to Wizer time, so we configure the engine here
2121
bool install(api::Engine *engine) {
22+
#if defined(JS_GC_ZEAL) && defined(FASTLY_GC_FREQUENCY)
23+
JS::SetGCZeal(engine->cx(), 2, FASTLY_GC_FREQUENCY);
24+
#endif
2225
ENGINE = engine;
2326
return true;
2427
}

0 commit comments

Comments
 (0)