Skip to content

perf(semantic): use match_module_declaration! macro instead of match guard#17184

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/12-20-perf_semantic_use_match_module_declaration_macro_instead_of_match_guard
Dec 22, 2025
Merged

perf(semantic): use match_module_declaration! macro instead of match guard#17184
graphite-app[bot] merged 1 commit intomainfrom
c/12-20-perf_semantic_use_match_module_declaration_macro_instead_of_match_guard

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Dec 20, 2025

Replaces the match guard pattern that calls is_module_declaration() for every AST node with the match_module_declaration! macro for direct pattern matching.

Before:

example::check_before::hfc46178bb9b4d182:
        cmp     rdi, 7
        ja      .LBB1_11
        lea     rax, [rip + .LJTI1_0]
        movsxd  rcx, dword ptr [rax + 4*rdi]
        add     rcx, rax
        jmp     rcx
.LBB1_2:
        mov     rdi, rsi
        jmp     example::check_program::hdcbd5472c2f04f3b
.LBB1_3:
        mov     eax, 3
        jmp     .LBB1_10
.LBB1_4:
        mov     eax, 1
        jmp     .LBB1_10
.LBB1_5:
        mov     eax, 2
        jmp     .LBB1_10
.LBB1_7:
        xor     eax, eax
        jmp     .LBB1_10
.LBB1_8:
        mov     eax, 4
        jmp     .LBB1_10
.LBB1_9:
        mov     eax, 5
.LBB1_10:
        sub     rsp, 24
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rsi
        lea     rdi, [rsp + 8]
        call    example::check_module_declaration::h47851d60ce069a6b
        add     rsp, 24
.LBB1_11:
        ret
.LJTI1_0:
        .long   .LBB1_2-.LJTI1_0
        .long   .LBB1_7-.LJTI1_0
        .long   .LBB1_4-.LJTI1_0
        .long   .LBB1_5-.LJTI1_0
        .long   .LBB1_3-.LJTI1_0
        .long   .LBB1_8-.LJTI1_0
        .long   .LBB1_9-.LJTI1_0
        .long   .LBB1_2-.LJTI1_0

After:

example::check_after::h7e9549e143229746:
        lea     rax, [rdi - 1]
        cmp     rax, 6
        jae     .LBB0_1
        sub     rsp, 24
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rsi
        lea     rdi, [rsp + 8]
        call    example::check_module_declaration::h47851d60ce069a6b
        add     rsp, 24
.LBB0_5:
        ret
.LBB0_1:
        test    rdi, rdi
        je      .LBB0_3
        cmp     rdi, 7
        jne     .LBB0_5
.LBB0_3:
        mov     rdi, rsi
        jmp     example::check_program::hdcbd5472c2f04f3b

@github-actions github-actions bot added A-semantic Area - Semantic C-performance Category - Solution not expected to change functional behavior, only performance labels Dec 20, 2025
@camc314 camc314 marked this pull request as ready for review December 20, 2025 15:54
@camc314 camc314 requested a review from Dunqing as a code owner December 20, 2025 15:54
Copy link
Contributor Author

camc314 commented Dec 20, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 20, 2025

CodSpeed Performance Report

Merging #17184 will not alter performance

Comparing c/12-20-perf_semantic_use_match_module_declaration_macro_instead_of_match_guard (c36ee14) with c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root (ff2620d)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314
Copy link
Contributor Author

camc314 commented Dec 20, 2025

nice:

Screenshot 2025-12-20 at 16 00 55 Screenshot 2025-12-20 at 16 01 52

@camc314 camc314 assigned overlookmotel and unassigned camc314 Dec 20, 2025
@overlookmotel
Copy link
Member

How are you finding these things?

@camc314
Copy link
Contributor Author

camc314 commented Dec 21, 2025

How are you finding these things?

Claude 😉 I asked it to analyze the built assembly of oxc_semantic example and look for stuff

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
Copy link
Member

Boshen commented Dec 22, 2025

Merge activity

…guard (#17184)

Replaces the match guard pattern that calls `is_module_declaration()` for every AST node with the `match_module_declaration!` macro for direct pattern matching.

Before:

```asm
example::check_before::hfc46178bb9b4d182:
        cmp     rdi, 7
        ja      .LBB1_11
        lea     rax, [rip + .LJTI1_0]
        movsxd  rcx, dword ptr [rax + 4*rdi]
        add     rcx, rax
        jmp     rcx
.LBB1_2:
        mov     rdi, rsi
        jmp     example::check_program::hdcbd5472c2f04f3b
.LBB1_3:
        mov     eax, 3
        jmp     .LBB1_10
.LBB1_4:
        mov     eax, 1
        jmp     .LBB1_10
.LBB1_5:
        mov     eax, 2
        jmp     .LBB1_10
.LBB1_7:
        xor     eax, eax
        jmp     .LBB1_10
.LBB1_8:
        mov     eax, 4
        jmp     .LBB1_10
.LBB1_9:
        mov     eax, 5
.LBB1_10:
        sub     rsp, 24
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rsi
        lea     rdi, [rsp + 8]
        call    example::check_module_declaration::h47851d60ce069a6b
        add     rsp, 24
.LBB1_11:
        ret
.LJTI1_0:
        .long   .LBB1_2-.LJTI1_0
        .long   .LBB1_7-.LJTI1_0
        .long   .LBB1_4-.LJTI1_0
        .long   .LBB1_5-.LJTI1_0
        .long   .LBB1_3-.LJTI1_0
        .long   .LBB1_8-.LJTI1_0
        .long   .LBB1_9-.LJTI1_0
        .long   .LBB1_2-.LJTI1_0

```

After:

```asm
example::check_after::h7e9549e143229746:
        lea     rax, [rdi - 1]
        cmp     rax, 6
        jae     .LBB0_1
        sub     rsp, 24
        mov     qword ptr [rsp + 8], rax
        mov     qword ptr [rsp + 16], rsi
        lea     rdi, [rsp + 8]
        call    example::check_module_declaration::h47851d60ce069a6b
        add     rsp, 24
.LBB0_5:
        ret
.LBB0_1:
        test    rdi, rdi
        je      .LBB0_3
        cmp     rdi, 7
        jne     .LBB0_5
.LBB0_3:
        mov     rdi, rsi
        jmp     example::check_program::hdcbd5472c2f04f3b

```
@graphite-app graphite-app bot force-pushed the c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root branch from ff2620d to 605a290 Compare December 22, 2025 13:50
@graphite-app graphite-app bot force-pushed the c/12-20-perf_semantic_use_match_module_declaration_macro_instead_of_match_guard branch from c36ee14 to 3886ddc Compare December 22, 2025 13:51
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 22, 2025
Base automatically changed from c/12-20-perf_semantic_use_swap_remove_instead_of_into_iter_.next_in_into_root to main December 22, 2025 13:57
@graphite-app graphite-app bot merged commit 3886ddc into main Dec 22, 2025
21 checks passed
@graphite-app graphite-app bot deleted the c/12-20-perf_semantic_use_match_module_declaration_macro_instead_of_match_guard branch December 22, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants