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

Region-based memory management #304

Open
ichiban opened this issue Jul 30, 2023 · 1 comment
Open

Region-based memory management #304

ichiban opened this issue Jul 30, 2023 · 1 comment

Comments

@ichiban
Copy link
Owner

ichiban commented Jul 30, 2023

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:

Some articles that might be related:

@ichiban
Copy link
Owner Author

ichiban commented Jul 8, 2024

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

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

1 participant