testsAndMisc/scripts/run_prettier_capped.sh
Krzysztof kuhy Rudnicki dffbdac091 perf(pre-commit): run prettier in its own systemd-run scope
Wrap pre-push prettier --check in a 1 GiB systemd-run scope so its Node
heap is independent of the outer 4 GiB pre-push cgroup, which has
already accumulated page-cache footprint from pytest/mypy/pylint/bandit
by the time prettier runs. Falls back to direct invocation when
systemd-run is unavailable.
2026-05-14 21:12:32 +02:00

27 lines
894 B
Bash
Executable File

#!/usr/bin/env bash
# Run prettier --check inside its own systemd-run scope so its memory
# budget is independent of the outer pre-push cgroup (which has already
# accumulated page-cache footprint from pytest/mypy/pylint/bandit).
#
# Falls back to a direct invocation when systemd-run is unavailable
# (CI / containers without systemd user instance).
set -euo pipefail
if [ $# -eq 0 ]; then
exit 0
fi
# Cap Node heap on top of the cgroup limit for belt-and-braces safety.
export NODE_OPTIONS="${NODE_OPTIONS:-} --max-old-space-size=768"
if command -v systemd-run >/dev/null 2>&1 \
&& systemctl --user is-active --quiet default.target 2>/dev/null \
|| command -v systemd-run >/dev/null 2>&1; then
exec systemd-run --user --scope --quiet --collect \
-p MemoryMax=1G \
-p MemorySwapMax=0 \
-- prettier --check "$@"
fi
exec prettier --check "$@"