Skip to content

Commit ee89c56

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents 163f008 + 489dc5c commit ee89c56

File tree

184 files changed

+121169
-98957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+121169
-98957
lines changed

.github/scripts/format_benchmark.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
"""Format benchmark comparison output with visual indicators for GitHub markdown."""
3+
4+
import re
5+
import sys
6+
7+
8+
def format_benchmark_output(content):
9+
"""Add visual formatting to benchmark comparison output."""
10+
lines = content.split("\n")
11+
formatted_lines = []
12+
13+
for line in lines:
14+
# Skip empty lines and headers
15+
if not line.strip() or line.startswith("|") and "---" in line:
16+
formatted_lines.append(line)
17+
continue
18+
19+
# Process benchmark result lines
20+
if "|" in line and ("faster" in line or "slower" in line):
21+
# Extract the speed factor (e.g., "1.23x faster" or "1.10x slower")
22+
speed_match = re.search(r"(\d+\.\d+)x\s+(faster|slower)", line)
23+
if speed_match:
24+
factor = float(speed_match.group(1))
25+
direction = speed_match.group(2)
26+
27+
# Add visual indicators based on performance
28+
if direction == "faster":
29+
# Green indicator for faster
30+
if factor >= 2.0:
31+
indicator = "🟢🟢" # Double green for 2x+ faster
32+
elif factor >= 1.1:
33+
indicator = "🟢" # Single green for 1.1x+ faster
34+
else:
35+
indicator = "⚪" # White for marginal improvement
36+
formatted_text = f"{indicator} **{speed_match.group(0)}**"
37+
else:
38+
# Red indicator for slower
39+
if factor >= 2.0:
40+
indicator = "🔴🔴" # Double red for 2x+ slower
41+
elif factor >= 1.1:
42+
indicator = "🔴" # Single red for 1.1x+ slower
43+
else:
44+
indicator = "⚪" # White for marginal slowdown
45+
formatted_text = f"{indicator} **{speed_match.group(0)}**"
46+
47+
# Replace the original text with formatted version
48+
line = line.replace(speed_match.group(0), formatted_text)
49+
elif "not significant" in line:
50+
# Add neutral indicator for non-significant changes
51+
line = re.sub(r"not significant", "⚪ not significant", line)
52+
53+
formatted_lines.append(line)
54+
55+
return "\n".join(formatted_lines)
56+
57+
58+
def main():
59+
if len(sys.argv) != 2:
60+
print("Usage: python format_benchmark.py <input_file>")
61+
sys.exit(1)
62+
63+
input_file = sys.argv[1]
64+
65+
try:
66+
with open(input_file, "r") as f:
67+
content = f.read()
68+
69+
formatted = format_benchmark_output(content)
70+
print(formatted)
71+
72+
except FileNotFoundError:
73+
print(f"Error: File '{input_file}' not found")
74+
sys.exit(1)
75+
except Exception as e:
76+
print(f"Error: {e}")
77+
sys.exit(1)
78+
79+
80+
if __name__ == "__main__":
81+
main()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Benchmark pull requests
2+
3+
on:
4+
issue_comment:
5+
types: [created, edited, deleted]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
run-benchmark:
11+
name: run benchmark
12+
runs-on: ubuntu-latest
13+
if: |
14+
(github.event_name == 'issue_comment' &&
15+
contains(github.event.comment.body, '/benchmark') &&
16+
github.event.issue.pull_request) ||
17+
(github.event_name == 'pull_request' &&
18+
contains(github.event.pull_request.body, '/benchmark'))
19+
steps:
20+
- name: Checkout PR branch
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # Needed to fetch main branch too
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: 3.13
28+
- name: Create a virtual environment
29+
run: |
30+
python -m venv .venv
31+
source ./.venv/bin/activate
32+
python -m pip install --upgrade pip
33+
pip install pyperf
34+
- name: Run benchmark on PR branch
35+
run: |
36+
source ./.venv/bin/activate
37+
make install-dev
38+
make install-dev-rs-release
39+
python benchmarks/parse.py --quiet --output bench_parse_pr.json
40+
python benchmarks/optimize.py --quiet --fast --output bench_optimize_pr.json
41+
- name: Checkout main branch into subdir
42+
run: |
43+
git fetch origin main
44+
git worktree add main-branch origin/main
45+
- name: Reset virtual environment
46+
run: |
47+
rm -rf .venv
48+
python -m venv .venv
49+
source ./.venv/bin/activate
50+
python -m pip install --upgrade pip
51+
pip install pyperf
52+
- name: Run benchmark on main branch
53+
run: |
54+
source ./.venv/bin/activate
55+
cd main-branch
56+
make install-dev
57+
make install-dev-rs-release
58+
python benchmarks/parse.py --quiet --output ../bench_parse_main.json
59+
python benchmarks/optimize.py --quiet --fast --output ../bench_optimize_main.json
60+
cd ..
61+
- name: Compare benchmarks and save results
62+
run: |
63+
source ./.venv/bin/activate
64+
python -m pyperf compare_to bench_parse_main.json bench_parse_pr.json --table --table-format=md > bench_parse_comparison_raw.txt
65+
python -m pyperf compare_to bench_optimize_main.json bench_optimize_pr.json --table --table-format=md > bench_optimize_comparison_raw.txt
66+
67+
# Format with colors
68+
python .github/scripts/format_benchmark.py bench_parse_comparison_raw.txt > bench_parse_comparison.txt
69+
python .github/scripts/format_benchmark.py bench_optimize_comparison_raw.txt > bench_optimize_comparison.txt
70+
- name: Combine benchmark outputs
71+
run: |
72+
echo "## Benchmark Results" > combined_benchmarks.md
73+
echo "" >> combined_benchmarks.md
74+
echo "**Legend:**" >> combined_benchmarks.md
75+
echo "- 🟢🟢 = 2x+ faster" >> combined_benchmarks.md
76+
echo "- 🟢 = 1.1x - 2x faster" >> combined_benchmarks.md
77+
echo "- ⚪ = No significant change (< 1.1x)" >> combined_benchmarks.md
78+
echo "- 🔴 = 1.1x - 2x slower" >> combined_benchmarks.md
79+
echo "- 🔴🔴 = 2x+ slower" >> combined_benchmarks.md
80+
echo "" >> combined_benchmarks.md
81+
echo "### Parsing Benchmark" >> combined_benchmarks.md
82+
cat bench_parse_comparison.txt >> combined_benchmarks.md
83+
echo -e "\n---\n" >> combined_benchmarks.md
84+
echo "### Optimization Benchmark" >> combined_benchmarks.md
85+
cat bench_optimize_comparison.txt >> combined_benchmarks.md
86+
- name: Comment on PR for parse benchmark results
87+
uses: peter-evans/create-or-update-comment@v4
88+
with:
89+
token: ${{ secrets.GITHUB_TOKEN }}
90+
issue-number: ${{ github.event.issue.number || github.event.pull_request.number }}
91+
body-file: combined_benchmarks.md

.github/workflows/rust-bench.yml renamed to .github/workflows/benchmark-sqlglotrs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
name: Benchmark Rust tokenizer changes
2+
13
on:
24
pull_request:
35
paths:
46
- 'sqlglotrs/**'
5-
name: benchmark pull requests
7+
68
jobs:
79
run-benchmark:
810
name: run benchmark

.github/workflows/python-publish.yml renamed to .github/workflows/package-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Python Release to PyPI
1+
name: Publish sqlglot and sqlglotrs to PyPI
22

33
on:
44
push:
@@ -55,13 +55,13 @@ jobs:
5555
- uses: actions/setup-python@v5
5656
if: matrix.os == 'windows'
5757
with:
58-
python-version: '3.8'
58+
python-version: '3.9'
5959
architecture: ${{ matrix.python-architecture || 'x64' }}
6060
- name: Build wheels
6161
uses: PyO3/maturin-action@v1
6262
with:
6363
target: ${{ matrix.target }}
64-
args: --release --out dist --interpreter 3.8 3.9 3.10 3.11 3.12 3.13
64+
args: --release --out dist --interpreter 3.9 3.10 3.11 3.12 3.13
6565
sccache: 'true'
6666
manylinux: auto
6767
working-directory: ./sqlglotrs
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
name: Test and Lint Python Package
1+
name: Run tests and linter checks
22

33
on:
44
push:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8+
89
jobs:
9-
build:
10+
run-checks:
1011
runs-on: ubuntu-22.04
1112
strategy:
1213
matrix:
13-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
14+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1415
steps:
15-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1617
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4
18+
uses: actions/setup-python@v5
1819
with:
1920
python-version: ${{ matrix.python-version }}
2021
cache: pip
@@ -26,7 +27,7 @@ jobs:
2627
source ./.venv/bin/activate
2728
python -m pip install --upgrade pip
2829
make install-dev
29-
- name: Run checks (linter, code style, tests)
30+
- name: Run tests and linter checks
3031
run: |
3132
source ./.venv/bin/activate
3233
make check

0 commit comments

Comments
 (0)