Skip to content

Speed and Memory Optimizations - #9

Merged
NJdevPro merged 3 commits into
masterfrom
extend
Nov 11, 2026
Merged

NJdevPro merged 3 commits into
masterfrom
extend

Conversation

@NJdevPro

Copy link
Copy Markdown
Owner
  1. stocker la valeur globale dans le symbole, pour accélérer find ;
  2. réduire l'en-tête des objets de 16 à 8 octets, pour économiser la mémoire et le GC ;
  3. ajouter la récursion terminale.

NJdevPro and others added 3 commits November 11, 2026 16:21
A symbol now has a "bind" field pointing to its (symbol . value) pair in the
global environment. find() only walks the local frames, then reads the field,
so the cost of a lookup no longer depends on the number of global definitions.
The GC follows the new pointer. fib(27) goes from 0.095s to 0.057s and a 3M
iterations while loop from 0.251s to 0.113s.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
type is now a uint8_t, line_num a 24 bit field (per file, so enough for any
source) and size a uint32_t, which fit together in 8 bytes. A cons cell takes
24 bytes instead of 32 and an integer 16 instead of 24: a list of 100000
integers uses 29% less memory. A compile-time check guards the header size.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
eval_form evaluates in a loop whose current expression and environment live
in its own GC root slots. The expression in tail position of a function body,
of an if, of a progn or of a macro expansion becomes the current expression
instead of being evaluated by a recursive call, so tail calls use no stack.
if and progn are recognized by eval_form itself.

A loop written as a tail recursion can now run for as long as needed, and the
maximum depth of the other recursions goes from about 6800 to 25000 calls.
fib(27) is 20% faster. Tests and README updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NJdevPro

Copy link
Copy Markdown
Owner Author

1.store symbol global value, to accelerate find ;
2.reduce ojects header from 16 to 8 bytes, to save RAM and GC;
3. Tail call optimization.

OK

@NJdevPro NJdevPro left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

1.store symbol global value, to accelerate find ;
2.reduce ojects header from 16 to 8 bytes, to save RAM and GC;
3. Tail call optimization.

OK

@NJdevPro
NJdevPro merged commit 9b3005e into master Nov 11, 2026
1 check passed
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.

1 participant