ichiban / prolog

The only reasonable scripting engine for Go.
MIT License
567 stars 27 forks source link

What would I measure, Prolog with or without garbage collection? #331

Open Jean-Luc-Picard-2021 opened 1 month ago

Jean-Luc-Picard-2021 commented 1 month ago

Lets say this feature request would be realized:

feature request time/1 and/or statistics/2 predicate https://github.com/ichiban/prolog/issues/327

What would I measure a Prolog system with or without garbage collection? Is this documented somewhere?

For example Scryer Prolog has no garbage collection, and it still fails with this test case:

$ ulimit -m 2000000
$ ulimit -v 2000000
$ target/release/scryer-prolog -v
v0.9.4-135-g7cfe8ee5

$ target/release/scryer-prolog
?- [user].
app([], X, X).
app([X|Y], Z, [X|T]) :- app(Y, Z, T).
garbage(0, [0]) :- !.
garbage(N, L) :- M is N-1, garbage(M, R), app(R, R, L).
foo :- garbage(12,_), foo.

?- foo.
memory allocation of 2147483648 bytes failed
Aborted

The above preferably runs indefinitely. For example SWI-Prolog can run it indefinitely.

Jean-Luc-Picard-2021 commented 1 month ago

Yeah it can also crash your Prolog system:

$ ~/go/bin/1pl
Top level for ichiban/prolog v1.2.1
This is for testing purposes only!
See https://github.com/ichiban/prolog for more details.
Type Ctrl-C or 'halt.' to exit.

?- ['bomb.p'].
true.
?- foo.
runtime: out of memory: cannot allocate 4194304-byte block (802816000 in use)

Thats the source code:

bomb.p.log

ichiban commented 1 month ago

I'm not sure if I understand your question but you can turn off GC with debug.SetGCPercent():

prev := debug.SetGCPercent(-1)
defer func() {
    _ = debug.SetGCPercent(prev)
}()
Jean-Luc-Picard-2021 commented 1 month ago

debug.SetGCPercent is only Go GC? Usually the host language GC is not enough for a Prolog system, you need additional algorithms to trim the environment, make

the variable trailing list smaller. Basically there are WAMs with this feature and WAMs without this feature. But environment trimming was already described in early WAM papers.

For example Scryer Prolog doesn't have Prolog GC yet. Whereas SWI-Prolog has a quite good Prolog GC.

So in SWI-Prolog you can run the bomb example indefinitely it will not crash, because it has Prolog GC.

ichiban commented 1 month ago

I'm afraid that this library is not based on WAM.