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,cgen: reduce memory usage for compiling larger v programs with long fns #18876

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Jul 15, 2023

This PR reduces the memory usage for compiling larger V programs with long functions.

With it:

#0 18:19:11 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱v run cmd/tools/gen_1long_fn.v 100_000 'a = b + c * d'
#0 18:19:17 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱xtime ./vold 100000.v 
parsed 100000 statements so far from fn main.main ...
CPU: 2.77s      Real: 2.90s     Elapsed: 0:02.90        RAM: 394116KB   ./vold 100000.v
#0 18:19:23 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱xtime ./vnew 100000.v 
parsed 100000 statements so far from fn main.main ...
CPU: 2.63s      Real: 2.73s     Elapsed: 0:02.73        RAM: 371864KB   ./vnew 100000.v
#0 18:19:28 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱

V self compilation also benefits, although much less:

#0 18:21:54 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱hyperfine './vprod_old -o x.c cmd/v' './vprod_new -o x.c cmd/v'
Benchmark #1: ./vprod_old -o x.c cmd/v
  Time (mean ± σ):     700.2 ms ±  10.5 ms    [User: 734.7 ms, System: 171.5 ms]
  Range (min … max):   682.4 ms … 718.1 ms    10 runs
 
Benchmark #2: ./vprod_new -o x.c cmd/v
  Time (mean ± σ):     693.2 ms ±   9.5 ms    [User: 720.7 ms, System: 168.3 ms]
  Range (min … max):   673.0 ms … 704.8 ms    10 runs
 
Summary
  './vprod_new -o x.c cmd/v' ran
    1.01 ± 0.02 times faster than './vprod_old -o x.c cmd/v'
#0 18:22:12 ᛋ reduce_memory_usage_for_compiling_larger_v_programs_with_long_fns /v/vnew❱
#0 18:23:09 ᛋ  /v/vnew❱xtime ./vprod_old -o x.c cmd/v
CPU: 0.75s      Real: 0.70s     Elapsed: 0:00.70        RAM: 304560KB   ./vprod_old -o x.c cmd/v
#0 18:23:20 ᛋ /v/vnew❱xtime ./vprod_new -o x.c cmd/v
CPU: 0.72s      Real: 0.70s     Elapsed: 0:00.70        RAM: 302556KB   ./vprod_new -o x.c cmd/v

@spytheman spytheman marked this pull request as draft July 15, 2023 15:24
@spytheman spytheman changed the title reduce memory usage for compiling larger v programs with long fns ast,cgen: reduce memory usage for compiling larger v programs with long fns Jul 15, 2023
@JalonSolov
Copy link
Contributor

You wrote gen_1long_fn.v like a script, but gave it a .v extension...

@spytheman spytheman added Needs Rebase The code of the PR must be rebased over current master before it can be approved. Breaking Change This PR introduces changes that break backward compatibility. Requires manual review. labels Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change This PR introduces changes that break backward compatibility. Requires manual review. Needs Rebase The code of the PR must be rebased over current master before it can be approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants