Region-based memory management
Since we took advantage of Go's memory management, we have a lot of pointers and interfaces which are pointers disguised.
This also lets us provide an approachable set of APIs, I hope, but comes with a cost of GC because the GC has to trace all the live terms.
type Term interface {
WriteTerm(w io.Writer, opts *WriteOptions, env *Env) error
Compare(t Term, env *Env) int
}
We might be able to provide a workable set of APIs while implementing a WAM-like region-based memory management.
type VM struct {
termCells []termCell
// ...
}
type Term uint32 // index to termCells
Related issues:
- https://github.com/ichiban/prolog/issues/238
- https://github.com/ichiban/prolog/issues/226
Some articles that might be related:
Atom may or may not be re-implemented as unique.Handle[string].
New unique package The new unique package provides facilities for canonicalizing values (like “interning” or “hash-consing”).
Any value of comparable type may be canonicalized with the new Make[T] function, which produces a reference to a canonical copy of the value in the form of a Handle[T]. Two Handle[T] are equal if and only if the values used to produce the handles are equal, allowing programs to deduplicate values and reduce their memory footprint. Comparing two Handle[T] values is efficient, reducing down to a simple pointer comparison.
https://tip.golang.org/doc/go1.23