From: ko1@... Date: 2019-06-04T05:00:24+00:00 Subject: [ruby-core:92947] [Ruby trunk Feature#15878] Make exit faster by not running GC Issue #15878 has been updated by ko1 (Koichi Sasada). > A rough sketch of the process is that we first run GC normally, then if something remains, that is force-recycled. No. We don't run GC at last. ```` diff --git a/gc.c b/gc.c index 19ddf9bf20..d9f83dfaf8 100644 --- a/gc.c +++ b/gc.c @@ -7183,6 +7183,7 @@ gc_enter(rb_objspace_t *objspace, const char *event) mjit_gc_start_hook(); during_gc = TRUE; + fprintf(stderr, "gc_enter: %s [%s]\n", event, gc_current_status(objspace)); gc_report(1, objspace, "gc_enter: %s [%s]\n", event, gc_current_status(objspace)); gc_record(objspace, 0, event); gc_event_hook(objspace, RUBY_INTERNAL_EVENT_GC_ENTER, 0); /* TODO: which parameter should be passed? */ ``` This patch shows GC events every time. Output: ``` $ ./miniruby -e 'a=[];10000.times{a<<[]}; p "to be exit"' gc_enter: gc_start [N] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: sweep_continue [SL] gc_enter: gc_start [N] gc_enter: sweep_continue [SL] "to be exit" gc_enter: rb_objspace_call_finalizer [N] ``` `rb_objspace_call_finalizer` run finalizers for all objects (don't collect, but run special finalize functions). ---------------------------------------- Feature #15878: Make exit faster by not running GC https://bugs.ruby-lang.org/issues/15878#change-78323 * Author: grosser (Michael Grosser) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I noticed that exit takes 0.2 ... I'm trying to write a fast cli, so any improvement here would be great or an option to opt-out of certain cleanup tasks exit! takes a constant low time ``` ruby -rbenchmark -e 'puts Benchmark.realtime { Process.wait(fork { exit }) }' # 0.03 great! ruby -rbenchmark -rrubocop -e 'puts Benchmark.realtime { Process.wait(fork { exit }) }' # 0.18 :( ruby -rbenchmark -rrubocop -e 'GC.disable; puts Benchmark.realtime { Process.wait(fork { exit }) }' # 0.04 :D ruby -rbenchmark -rrubocop -e 'puts Benchmark.realtime { Process.wait(fork { exit! }) }' # 0.002 ... fast but unsafe ``` -- https://bugs.ruby-lang.org/ Unsubscribe: