Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick "AK+LibJS: Performance improvements for resolving large rope strings" #25131

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nico
Copy link
Contributor

@nico nico commented Oct 17, 2024

This feature is unused in Ladybird and will complicate an upcoming patch
to hand-off StringBuilder's memory to String.

(cherry picked from commit af220af8bf15f9eb297a165e6d2ae3bf5bbc49fc)
Opening StringData.h in any clangd-enabled editor previously resulted in
a sea of clangd errors.

(cherry picked from commit 77eef8a8f6723b1e2fb5107aac7cf39bc1b40dad)
Currently, invoking StringBuilder::to_string will re-allocate the string
data to construct the String. This is wasteful both in terms of memory
and speed.

The goal here is to simply hand the string buffer over to String, and
let String take ownership of that buffer. To do this, StringBuilder must
have the same memory layout as Detail::StringData. This layout is just
the members of the StringData class followed by the string itself.

So when a StringBuilder is created, we reserve sizeof(StringData) bytes
at the front of the buffer. StringData can then construct itself into
the buffer with placement new.

Things to note:
* StringData must now be aware of the actual capacity of its buffer, as
  that can be larger than the string size.
* We must take care not to pass ownership of inlined string buffers, as
  these live on the stack.

(cherry picked from commit 29879a69a4b2eda4f0315027cb1e86964d333221;
amended minor conflict in AK/String.h due to us not having
String::from_utf16() from LadybirdBrowser/ladybird#674, last commit)
For performance, rather than slowly incrementing the capacity of the
rope string's buffer, compute an approximate length for that buffer to
be reserved up front.

(cherry picked from commit e8f4ae487d228dac491a446ed548400176331ae9)
@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 17, 2024
@nico nico marked this pull request as draft October 17, 2024 02:17
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 17, 2024
Copy link

stale bot commented Nov 9, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@stale stale bot added the stale label Nov 9, 2024
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