Skip to content

perf: memoize env lookups across top-level forms - #1599

Draft
eriksvedang wants to merge 5 commits into
masterfrom
avoid-billions-of-allocations
Draft

eriksvedang wants to merge 5 commits into
masterfrom
avoid-billions-of-allocations

Conversation

@eriksvedang

@eriksvedang eriksvedang commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

This is a follow up PR to #1598 (it contains its changes too).

It makes things super fast but needs thorough review before we merge it. I just pushed it so that interested parties can try it out :)

Disclosure: also written by Claude

@eriksvedang eriksvedang changed the title perf: avoid allocations perf: memoize env lookups across top-level forms. Oct 16, 2026
@eriksvedang eriksvedang changed the title perf: memoize env lookups across top-level forms. perf: memoize env lookups across top-level forms Oct 16, 2026
Comment thread src/Concretize.hs
if instancePath `elem` visitedDefinitions
-- Already defined by an earlier form: it and its own dependencies
-- are in the environment, so concretizing it again is wasted work.
if instancePath `elem` visitedDefinitions || isDefinedInstance instancePath

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this means i cannot override deleters anymore if i already had an instance. concretely, the new check skips an existing specialization without checking whether its source changed.

i specced out a repro with codex:

(deftype (Crate a) [value a])

(defmodule Crate
  (sig delete (Fn [(Crate a)] ()))
  (defn delete [x] (IO.println "old")))

; we find it here and specialize
(defn before []
  (let [x (Crate.init 1)] ()))

(defmodule Crate
  (defn delete [x] (IO.println "new")))

; old deleter here too
(defn main [] (let [x (Crate.init 2)] ()))

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants