Skip to content

Comments

Optimize memory usage for 2 core functions#10

Merged
gbuisson merged 2 commits intomasterfrom
optims
Aug 29, 2025
Merged

Optimize memory usage for 2 core functions#10
gbuisson merged 2 commits intomasterfrom
optims

Conversation

@gbuisson
Copy link
Contributor

During our load tests we noticed heavy memory usage for both is-sub-list? and repr-is-subscope?.
while their implementation is perfectly readable and favors maintenability, we can slightly tweak them to improve performance, this is an attempt at it, keeping a conservative approach while slightly tunning the code to reduce the memory footprint.

@gbuisson gbuisson self-assigned this Aug 11, 2025
Copy link
Contributor

@yogsototh yogsototh left a comment

Choose a reason for hiding this comment

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

I checked with criterium, this is slightly faster, not sure however how to check if this will use more or less memory.

Edit: I could test:

Initial used heap: 61.1 MiB (1.5%)
│ 
│ (scopula.core-bench/t <184 B>) | Heap: +504 B (+0.0%)
│ │ 
│ │ (scopula.core/is-sub-list? <416 B> <416 B>) | Heap: +21.8 KiB (+0.0%)
│ │ │ 
│ │ └─→ <16 B> | Heap: +35.1 KiB (+0.0%)
│ │ 
│ └─→ <16 B> | Heap: +34.8 KiB (+0.0%)
Final used heap: +34.7 KiB (+0.0%)

The new version:

Initial used heap: 61.2 MiB (1.5%)
│ 
│ (scopula.core-bench/t <192 B>) | Heap: +456 B (+0.0%)
│ │ 
│ │ (scopula.core-bench/is-sub-list-2 <416 B> <416 B>) | Heap: +3.5 KiB (+0.0%)
│ │ │ 
│ │ └─→ <16 B> | Heap: +9.4 KiB (+0.0%)
│ │ 
│ └─→ <16 B> | Heap: +9.8 KiB (+0.0%)
Final used heap: +9.7 KiB (+0.0%)

@gbuisson gbuisson merged commit 1fa4c1e into master Aug 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants