diff --git a/pkgs/racket-doc/scribblings/guide/performance.scrbl b/pkgs/racket-doc/scribblings/guide/performance.scrbl index 555fd3345f..6fade46141 100644 --- a/pkgs/racket-doc/scribblings/guide/performance.scrbl +++ b/pkgs/racket-doc/scribblings/guide/performance.scrbl @@ -613,7 +613,10 @@ immediate garbage collection, but instead requests that each minor collection perform incremental work up to the next major collection. The request expires with the next major collection. Make a call to @racket[(collect-garbage 'incremental)] in any periodic task within -an application that needs to be responsive in real time. +an application that needs to be responsive in real time. Force a +full collection with @racket[(collect-garbage)] just before an initial +@racket[(collect-garbage 'incremental)] to initiate incremental mode +from an optimal state. To check whether incremental mode is use and how it affects pause times, enable @tt{debug}-level logging output for the diff --git a/racket/src/racket/gc2/newgc.c b/racket/src/racket/gc2/newgc.c index 29eb834a98..8fa4ac7f22 100644 --- a/racket/src/racket/gc2/newgc.c +++ b/racket/src/racket/gc2/newgc.c @@ -5811,6 +5811,9 @@ static void garbage_collect(NewGC *gc, int force_full, int no_full, int switchin incremental mode has been enabled: */ || ((gc->since_last_full > FORCE_MAJOR_AFTER_COUNT) && !gc->started_incremental) + || (gc->full_needed_for_finalization + && !gc->incremental_requested + && !gc->started_incremental) /* In incremental mode, GC earlier if we've done everything that we can do incrementally. */ || (gc->started_incremental @@ -5823,12 +5826,13 @@ static void garbage_collect(NewGC *gc, int force_full, int no_full, int switchin return; } - next_gc_full = gc->gc_full && !gc->started_incremental; + next_gc_full = (gc->gc_full + && !gc->started_incremental + && !gc->full_needed_for_finalization); - if (gc->full_needed_for_finalization) { + if (gc->full_needed_for_finalization && gc->gc_full) gc->full_needed_for_finalization= 0; - gc->gc_full = 1; - } + #ifdef GC_DEBUG_PAGES if (gc->gc_full == 1) { GCVERBOSEprintf(gc, "GC_FULL gc: %p MASTER: %p\n", gc, MASTERGC);