Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ast: reduce allocations in empty_comptime_const_expr #23324

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Dec 30, 2024

Improve compiler performance a bit, by reducing the amount of small allocations, for creating ComptTimeConstValue(EmptyExpr(0)) for the default field values of the AST nodes.

Huly®: V_0.6-21756

@spytheman
Copy link
Member Author

Here is the comparison with master:

#0 22:50:02 ^ ast_reduce_allocation_in_empty_comptime_const_expr ~/code/v>./v run .github/workflows/compare_pr_to_master.v
==================================================================================================
Current git branch: ast_reduce_allocation_in_empty_comptime_const_expr, commit: 5b8d9e4
    Compiling new V executables from PR branch: ast_reduce_allocation_in_empty_comptime_const_expr, commit: 5b8d9e4 ...
CPU: 2.80s      Real: 2.51s     Elapsed: 0:02.51        RAM: 432596KB   ./v -o vnew1 cmd/v
CPU: 2.71s      Real: 2.48s     Elapsed: 0:02.48        RAM: 432612KB   ./vnew1 -o vnew2 cmd/v
CPU: 2.51s      Real: 2.73s     Elapsed: 0:02.73        RAM: 415988KB   ./vnew2 -no-parallel -o vnew cmd/v
CPU: 0.16s      Real: 0.18s     Elapsed: 0:00.18        RAM: 44944KB    ./vnew -no-parallel -o nhw_current.c examples/hello_world.v
CPU: 2.10s      Real: 2.31s     Elapsed: 0:02.31        RAM: 416024KB   ./vnew -no-parallel -o nv_current.c cmd/v
>Size of        nhw_current.c:      45403
>Size of         nv_current.c:    6184087
>Size of                 vnew:    9540136
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
==================================================================================================
    Compiling old V executables from branch: master, commit: d9e505b ...
CPU: 2.73s      Real: 2.48s     Elapsed: 0:02.48        RAM: 432472KB   ./v -o vold1 cmd/v
CPU: 2.73s      Real: 2.48s     Elapsed: 0:02.48        RAM: 434032KB   ./vold1 -o vold2 cmd/v
CPU: 2.49s      Real: 2.72s     Elapsed: 0:02.72        RAM: 417368KB   ./vold2 -no-parallel -o vold cmd/v
CPU: 0.16s      Real: 0.18s     Elapsed: 0:00.18        RAM: 45168KB    ./vold -no-parallel -o ohw_master.c examples/hello_world.v
CPU: 2.10s      Real: 2.33s     Elapsed: 0:02.33        RAM: 417476KB   ./vold -no-parallel -o ov_master.c cmd/v
>Size of         ohw_master.c:      45403
>Size of          ov_master.c:    6183975
>Size of                 vold:    9539928
==================================================================================================
File sizes so far ...
>>>>>> size("  nhw_current.c") - size("   ohw_master.c") =      45403 -      45403 =          0
>>>>>> size("   nv_current.c") - size("    ov_master.c") =    6184087 -    6183975 =        112
>>>>>> size("           vnew") - size("           vold") =    9540136 -    9539928 =        208
Switched to branch 'ast_reduce_allocation_in_empty_comptime_const_expr'
==================================================================================================
    Measuring at PR branch: ast_reduce_allocation_in_empty_comptime_const_expr, commit: 5b8d9e4 ...
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.9% 1.02x faster 110.4ms ± σ:   0.1ms, 110.2ms…110.6ms `./vnew -check-syntax           examples/hello_world.v`
 >  2         base         112.6ms ± σ:   0.0ms, 112.5ms…112.6ms `./vold -check-syntax           examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -1.3% 1.01x faster 110.9ms ± σ:   0.3ms, 110.5ms…111.2ms `./vnew -check-syntax           examples/hello_world.v`
 >  2         base         112.3ms ± σ:   0.0ms, 112.2ms…112.3ms `./vold -check-syntax           examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.6% 1.02x faster 110.4ms ± σ:   0.1ms, 110.3ms…110.5ms `./vnew -check-syntax           examples/hello_world.v`
 >  2         base         112.3ms ± σ:   0.2ms, 112.0ms…112.4ms `./vold -check-syntax           examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.4% 1.01x faster 163.8ms ± σ:   0.2ms, 163.6ms…164.0ms `./vnew -check                  examples/hello_world.v`
 >  2         base         166.1ms ± σ:   0.2ms, 165.9ms…166.3ms `./vold -check                  examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -1.2% 1.01x faster 163.8ms ± σ:   0.1ms, 163.7ms…163.9ms `./vnew -check                  examples/hello_world.v`
 >  2         base         165.9ms ± σ:   0.2ms, 165.6ms…166.2ms `./vold -check                  examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.3% 1.01x faster 163.5ms ± σ:   0.2ms, 163.4ms…163.8ms `./vnew -check                  examples/hello_world.v`
 >  2         base         165.7ms ± σ:   0.2ms, 165.6ms…166.0ms `./vold -check                  examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.0% 1.01x faster 183.6ms ± σ:   0.2ms, 183.4ms…183.8ms `./vnew -no-parallel -o nhw.c   examples/hello_world.v`
 >  2         base         185.5ms ± σ:   0.3ms, 185.2ms…185.8ms `./vold -no-parallel -o ohw.c   examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -1.6% 1.02x faster 183.0ms ± σ:   0.1ms, 183.0ms…183.1ms `./vnew -no-parallel -o nhw.c   examples/hello_world.v`
 >  2         base         186.0ms ± σ:   0.2ms, 185.8ms…186.3ms `./vold -no-parallel -o ohw.c   examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.5% 1.01x faster 183.5ms ± σ:   0.0ms, 183.5ms…183.5ms `./vnew -no-parallel -o nhw.c   examples/hello_world.v`
 >  2         base         186.2ms ± σ:   0.2ms, 186.0ms…186.3ms `./vold -no-parallel -o ohw.c   examples/hello_world.v`
>>>>>> size("          nhw.c") - size("          ohw.c") =      45403 -      45403 =          0
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.2% 1.01x faster 194.9ms ± σ:   0.1ms, 194.8ms…195.0ms `./vnew -no-parallel -o nhw.exe examples/hello_world.v`
 >  2         base         197.2ms ± σ:   0.3ms, 196.8ms…197.6ms `./vold -no-parallel -o ohw.exe examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -1.3% 1.01x faster 194.7ms ± σ:   0.1ms, 194.7ms…194.8ms `./vnew -no-parallel -o nhw.exe examples/hello_world.v`
 >  2         base         197.4ms ± σ:   0.2ms, 197.2ms…197.6ms `./vold -no-parallel -o ohw.exe examples/hello_world.v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.3% 1.01x faster 194.6ms ± σ:   0.1ms, 194.5ms…194.8ms `./vnew -no-parallel -o nhw.exe examples/hello_world.v`
 >  2         base         197.2ms ± σ:   0.1ms, 197.1ms…197.2ms `./vold -no-parallel -o ohw.exe examples/hello_world.v`
>>>>>> size("        nhw.exe") - size("        ohw.exe") =     242376 -     242376 =          0
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.4% 1.01x faster 915.5ms ± σ:   0.1ms, 915.5ms…915.7ms `./vnew -check-syntax           cmd/v`
 >  2         base         928.6ms ± σ:   1.0ms, 927.3ms…929.7ms `./vold -check-syntax           cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -1.6% 1.02x faster 915.1ms ± σ:   0.4ms, 914.6ms…915.5ms `./vnew -check-syntax           cmd/v`
 >  2         base         929.9ms ± σ:   0.6ms, 929.1ms…930.5ms `./vold -check-syntax           cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.6% 1.02x faster 914.2ms ± σ:   0.3ms, 913.8ms…914.4ms `./vnew -check-syntax           cmd/v`
 >  2         base         928.7ms ± σ:   0.7ms, 927.8ms…929.2ms `./vold -check-syntax           cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -1.0% 1.01x faster 1547.6ms ± σ:   0.4ms, 1547.1ms…1548.0ms `./vnew -check                  cmd/v`
 >  2         base         1564.0ms ± σ:   0.7ms, 1563.1ms…1564.8ms `./vold -check                  cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -0.9% 1.01x faster 1548.0ms ± σ:   1.0ms, 1546.5ms…1548.9ms `./vnew -check                  cmd/v`
 >  2         base         1562.4ms ± σ:   0.7ms, 1561.5ms…1563.1ms `./vold -check                  cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -1.1% 1.01x faster 1548.8ms ± σ:   0.0ms, 1548.8ms…1548.9ms `./vnew -check                  cmd/v`
 >  2         base         1565.9ms ± σ:   0.7ms, 1564.9ms…1566.5ms `./vold -check                  cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -0.7% 1.01x faster 2315.3ms ± σ:   0.5ms, 2314.9ms…2316.0ms `./vnew -no-parallel -o nv.c    cmd/v`
 >  2         base         2331.2ms ± σ:   0.4ms, 2331.0ms…2331.8ms `./vold -no-parallel -o ov.c    cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -0.6% 1.01x faster 2315.4ms ± σ:   0.2ms, 2315.2ms…2315.7ms `./vnew -no-parallel -o nv.c    cmd/v`
 >  2         base         2329.6ms ± σ:   1.5ms, 2327.6ms…2331.0ms `./vold -no-parallel -o ov.c    cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -0.7% 1.01x faster 2314.9ms ± σ:   1.1ms, 2313.9ms…2316.5ms `./vnew -no-parallel -o nv.c    cmd/v`
 >  2         base         2330.8ms ± σ:   0.3ms, 2330.4ms…2331.0ms `./vold -no-parallel -o ov.c    cmd/v`
>>>>>> size("           nv.c") - size("           ov.c") =    6184087 -    6184087 =          0
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  1
    1   -0.7% 1.01x faster 2709.5ms ± σ:   0.8ms, 2708.4ms…2710.4ms `./vnew -no-parallel -o nv.exe  cmd/v`
 >  2         base         2727.2ms ± σ:   0.4ms, 2726.9ms…2727.7ms `./vold -no-parallel -o ov.exe  cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  2
    1   -0.7% 1.01x faster 2710.8ms ± σ:   1.3ms, 2709.4ms…2712.4ms `./vnew -no-parallel -o nv.exe  cmd/v`
 >  2         base         2729.4ms ± σ:   0.2ms, 2729.2ms…2729.6ms `./vold -no-parallel -o ov.exe  cmd/v`
Summary after 1 series x 10 runs (%s are relative to first command, or `base`), discard maxs:  7, repeat:  3
    1   -0.6% 1.01x faster 2710.6ms ± σ:   1.2ms, 2709.4ms…2712.2ms `./vnew -no-parallel -o nv.exe  cmd/v`
 >  2         base         2727.4ms ± σ:   0.1ms, 2727.3ms…2727.6ms `./vold -no-parallel -o ov.exe  cmd/v`
>>>>>> size("         nv.exe") - size("         ov.exe") =    9540136 -    9540136 =          0
Done. Total time: 610.594590796 s.
==================================================================================================
Final summary for file diff sizes on their own branches:
>>>>>> size("  nhw_current.c") - size("   ohw_master.c") =      45403 -      45403 =          0
>>>>>> size("   nv_current.c") - size("    ov_master.c") =    6184087 -    6183975 =        112
>>>>>> size("           vnew") - size("           vold") =    9540136 -    9539928 =        208
==================================================================================================
Final summary for file diff sizes for generated files on the *current* branch:
>>>>>> size("          nhw.c") - size("          ohw.c") =      45403 -      45403 =          0
>>>>>> size("           nv.c") - size("           ov.c") =    6184087 -    6184087 =          0
>>>>>> size("        nhw.exe") - size("        ohw.exe") =     242376 -     242376 =          0
>>>>>> size("         nv.exe") - size("         ov.exe") =    9540136 -    9540136 =          0
#0 23:00:15 ^ ast_reduce_allocation_in_empty_comptime_const_expr ~/code/v>

@spytheman spytheman merged commit 4b6b852 into vlang:master Dec 31, 2024
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant