|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script runs memory comparisons for the Prism parser in the Sorbet type checker. |
| 4 | +# It assumes the presence of a few directories and tools: |
| 5 | +# - The yjit-bench directory, which contains the benchmarks for YJIT (https://github.com/Shopify/yjit-bench) |
| 6 | +# - The Shopify directory, which contains the Shopify codebase (https://github.com/Shopify/shopify) |
| 7 | +# - gtime, a command-line time and memory analysis tool (https://www.gnu.org/software/time/) |
| 8 | + |
| 9 | +# ----- Setup ----- |
| 10 | + |
| 11 | +YJIT_BENCH_DIR="../yjit-bench" |
| 12 | +SHOPIFY_DIR="../../Shopify/shopify" |
| 13 | +export SORBET_SILENCE_DEV_MESSAGE=1 |
| 14 | + |
| 15 | +# Check if required directories exist |
| 16 | +for dir in "$YJIT_BENCH_DIR" "$SHOPIFY_DIR"; do |
| 17 | + if [ ! -d "$dir" ]; then |
| 18 | + echo "Please clone the required directories before running this script." |
| 19 | + exit 1 |
| 20 | + fi |
| 21 | +done |
| 22 | + |
| 23 | +# Check and install gtime if necessary |
| 24 | +if ! command -v gtime &> /dev/null; then |
| 25 | + echo "Installing gtime..." |
| 26 | + if [[ "$OSTYPE" == "darwin"* ]]; then |
| 27 | + brew install gnu-time |
| 28 | + else |
| 29 | + echo "Please install gtime: https://www.gnu.org/software/time/" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +fi |
| 33 | + |
| 34 | +output_file_name="$(date '+%Y-%m-%d')-$(git rev-parse --short HEAD).txt" |
| 35 | +parsers=("prism" "sorbet") |
| 36 | + |
| 37 | +# ----- Run Benchmarks ----- |
| 38 | + |
| 39 | +run_benchmark() { |
| 40 | + local title="$1" |
| 41 | + local output_dir="$2" |
| 42 | + local command="$3" |
| 43 | + |
| 44 | + echo "#### $title ####" |
| 45 | + output_file="prism_benchmarks/memory/data/$output_dir/${output_file_name}" |
| 46 | + |
| 47 | + for parser in "${parsers[@]}"; do |
| 48 | + gtime --verbose --output="$output_file" --append \ |
| 49 | + bazel-bin/main/sorbet --parser=$parser $command &> /dev/null |
| 50 | + echo "" >> "$output_file" |
| 51 | + # Calculate peak memory usage: |
| 52 | + # - Search for lines that contain peak memory usage info |
| 53 | + # - Take the last one |
| 54 | + # - Extract the memory usage value |
| 55 | + # - Convert it to MB |
| 56 | + peak_memory=$(grep "Maximum resident set size (kbytes):" "$output_file" | tail -n 1 | awk '{print $6/1024 " MB"}') |
| 57 | + echo "-> Peak Memory Usage with $parser parser: $peak_memory" |
| 58 | + done |
| 59 | + echo "" |
| 60 | +} |
| 61 | + |
| 62 | +run_benchmark "Memory Check 1: yjit-bench, parser only" "parser/yjit-bench" "--stop-after=parser $YJIT_BENCH_DIR/benchmarks" |
| 63 | +run_benchmark "Memory Check 2: shopify, parser only" "parser/shopify" "--stop-after=parser $SHOPIFY_DIR" |
| 64 | +run_benchmark "Memory Check 3: prism regression tests, whole pipeline" "pipeline" "test/prism_regression" |
0 commit comments