Skip to content

Fix memory usage#3

Open
filippoliverani wants to merge 2 commits into
mainfrom
filippoliverani/fix-memory-usage
Open

Fix memory usage#3
filippoliverani wants to merge 2 commits into
mainfrom
filippoliverani/fix-memory-usage

Conversation

@filippoliverani
Copy link
Copy Markdown

@filippoliverani filippoliverani commented May 22, 2026

This PR changes Fragments::StructuredText#as_html to reduce memory allocation. The original implementation used an extremely inefficient character-by-character string concatenation.

Copy link
Copy Markdown

@AlessioRocco AlessioRocco left a comment

Choose a reason for hiding this comment

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

Solid work. The core memory fix is correct and well-executed — switching from character-by-character iteration to boundary-based slicing is exactly the right approach, and the use of String.new + << throughout is consistent and intentional. The hashery removal is clean and the plain-Ruby LRU reimplementation is sound. One nit inline, otherwise happy to approve.

Comment thread lib/prismic/cache/lru.rb
@intern.delete(key)
@intern[key] = { data: value, expired_in: expired_in && Time.now.getutc.to_i + expired_in }
@intern.delete(@intern.keys.first) while @intern.size > @max_size
value
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: @intern.keys.first allocates a full keys array on every call. Prefer @intern.shift — it pops the oldest entry (insertion-order head) in-place without the intermediate allocation:

@intern.shift while @intern.size > @max_size

Copy link
Copy Markdown

@schimpf schimpf left a comment

Choose a reason for hiding this comment

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

Code checked, looks good. Also tests are passing. We have to do a big regression test on the marketplace repot when we use this though.

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.

3 participants