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

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

Open
Jean-Luc-Picard-2021 opened this issue Aug 11, 2024 · 4 comments

Comments

@Jean-Luc-Picard-2021
Copy link

Jean-Luc-Picard-2021 commented Aug 11, 2024

Lets say this feature request would be realized:

feature request time/1 and/or statistics/2 predicate
#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
Copy link
Author

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
Copy link
Owner

ichiban commented Aug 14, 2024

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
Copy link
Author

Jean-Luc-Picard-2021 commented Aug 14, 2024

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
Copy link
Owner

ichiban commented Aug 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants