Skip to content

[CHIA-3002] optimize edge cases of concat#583

Merged
arvidn merged 1 commit intomainfrom
cat-optimization
Jun 5, 2025
Merged

[CHIA-3002] optimize edge cases of concat#583
arvidn merged 1 commit intomainfrom
cat-optimization

Conversation

@arvidn
Copy link
Contributor

@arvidn arvidn commented Jun 4, 2025

In the case where a single argument is passed to concat, we can return the same node. In the case where 0 arguments are passed to concat, we can return NIL. Any NIL arguments passed to concat can be omitted, funnelling those cases towards one of the previous edge cases.

The current implementation copies the bytes on the heap of the node into a new allocation, returning a new node pointing to that heap region. This wastes memory in the case of a single node.

However, we impose limits on node count and heap size. In order to make these optimizations maintain the same behavior , we need to account for optimized away heap space. This patch calls it ghost_heap and harmonizes the naming of the similar counters to ghost_atoms and ghost_pairs. Those also track atoms and pairs that count against the limit, but were optimized away.

@arvidn arvidn force-pushed the cat-optimization branch from ee810d4 to fc9d365 Compare June 4, 2025 10:50
@coveralls-official
Copy link

coveralls-official bot commented Jun 4, 2025

Pull Request Test Coverage Report for Build 15463536475

Details

  • 68 of 68 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 94.329%

Totals Coverage Status
Change from base Build 15209766231: 0.03%
Covered Lines: 6920
Relevant Lines: 7336

💛 - Coveralls

@arvidn arvidn force-pushed the cat-optimization branch from fc9d365 to 228d860 Compare June 4, 2025 11:38
@arvidn arvidn changed the title optimize edge cases of concat [CHIA-3002] optimize edge cases of concat Jun 5, 2025
@arvidn arvidn requested a review from richardkiss June 5, 2025 09:18
…e don't actually need to create a new atom. Filter out any empty terms passed in as well
@arvidn arvidn force-pushed the cat-optimization branch from 228d860 to 0ef74c7 Compare June 5, 2025 09:29
@richardkiss
Copy link
Contributor

Seems reasonable. I dunno if it's worth the effort, although the effort is spent now. :)

@arvidn arvidn merged commit c811cef into main Jun 5, 2025
33 checks passed
@arvidn arvidn deleted the cat-optimization branch June 5, 2025 21:30
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