Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Some data has to exist specifically for the navigation of one page to another. For example, if a hyperlink is clicked, the URL begins its life with the original page, but is transferred to the new page. The page_arena cannot be used for such data.

It's possible to use the session_arena, but it's lifetime is much longer and, given enough navigation, could accumulate a lot of memory.

The new transfer_arena exists within the session, but only exists until the next navigation.

While currently only used for the navigation URL, the main goal here is to have a place to put the request body on form submission, which has a lifetime similar to a click url.

While I'm at it, I promoted the existing session arena and the new transfer arena to the browser, allowing better memory re-use between sessions.

Some data has to exist specifically for the navigation of one page to another.
For example, if a hyperlink is clicked, the URL begins its life with the
original page, but is transferred to the new page. The page_arena cannot be used
for such data.

It's possible to use the session_arena, but it's lifetime is much longer and,
given enough navigation, could accumulate a lot of memory.

The new transfer_arena exists within the session, but only exists until the
next navigation.

While currently only used for the navigation URL, the main goal here is to have
a place to put the request body on form submission, which has a lifetime similar
to a click url.

While I'm at it, I promoted the existing session arena and the new transfer
arena to the browser, allowing better memory re-use between sessions.
var buf: [2048]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buf);
const url = try self.page.?.url.resolve(fba.allocator(), url_string);
_ = self.browser.transfer_arena.reset(.{ .retain_with_limit = 1 * 1024 * 1024 });
Copy link
Member

Choose a reason for hiding this comment

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

It surprises me the transfer_arena is reset at the beginning of the page navigate.
What about instead reset the transfer_arena after the end of pageNavigate? The data must live longer?

If we reset it at the beginning of the pageNavigate it must be explicit we shouldn't use it outside the function...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't thinking. I originally had the reset inside page.navigate, but I was happier with the page knowing nothing about it. Don't know why I didn't think of just defer inside the function.

@karlseguin karlseguin merged commit ad1a4fe into main May 17, 2025
9 checks passed
@karlseguin karlseguin deleted the transfer_arena branch May 17, 2025 01:44
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants