SWIP v 10.1.20, MacOS, Apple silicon
With the “exact” CPU profiler, I’ve been paying more attention to the impact of the garbage collector. My simple peg_parse BM is indicating 5-10% of the time is spent in GC. That was a bit of a surprise since I didn’t think this short BM (~25,000 inferences) produced much garbage to be collected.
Using a small predicate to output GC statistics:
get_garbage(G,GCs,CellsGained) :-
garbage_collect,
statistics(garbage_collection,[GC0,By0,_,_]),
G,
statistics(garbage_collection,[GC1,By1,_,_]),
GCs is GC1-GC0,
CellsGained is (By1-By0)/8. % 8 bytes/cell
I get:
?- peg_grammar(_G), get_garbage(peg_parse(pPEG,_G,_T),GCs,Cells).
GCs = 2,
Cells = 35368.
For this small BM, it seems like a lot of memory recovered. (Intel Macs give a similar result but only 1 GC reported.) With all the available stack memory, why is GC even being activated (twice)? Is some of this tunable?
I generally assume that terms created would be freed on backtracking, and would not depend on the GC to free space.
Other than terms created through unification, other possible sources of garbage include =.. (univ) and string ops (e.g., substring). Since there should be no references to them upon backtracking, they shouldn’t be any different (?).
Are there any tools which would help to identify (unexpected) sources of garbage?
