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

Refactor RawJsString's representation to make JsStrings construction from string literal heap-allocation free #3935

Merged
merged 19 commits into from
Aug 12, 2024

Conversation

CrazyboyQCD
Copy link
Contributor

@CrazyboyQCD CrazyboyQCD commented Jul 23, 2024

This changes RawJsString's representation, RawJsString in JsString is now a memory variant of RawJsString and StaticJsString which holds a string literal. It has a few benefits we can gain:

  • Memory-safe (passes miri, thanks to @jedel1043 )
  • JsString could be constant now
  • No allocation when JsString is created from string literal by using js_string macro

@CrazyboyQCD CrazyboyQCD changed the title Use union to represent RawJsString Refactor RawJsString to make JsString created from string literal without heap allocation Jul 23, 2024
@CrazyboyQCD CrazyboyQCD changed the title Refactor RawJsString to make JsString created from string literal without heap allocation Refactor RawJsString's representaion to make JsStrings construction from string literal heap-allocation free Jul 23, 2024
@CrazyboyQCD CrazyboyQCD marked this pull request as ready for review July 23, 2024 09:35
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

Attention: Patch coverage is 79.16667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 51.57%. Comparing base (6ddc2b4) to head (1cbec41).
Report is 221 commits behind head on main.

Files Patch % Lines
core/string/src/lib.rs 78.26% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3935       /-   ##
==========================================
  Coverage   47.24%   51.57%    4.33%     
==========================================
  Files         476      468       -8     
  Lines       46892    44983    -1909     
==========================================
  Hits        22154    23202     1048     
  Misses      24738    21781    -2957     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jedel1043 jedel1043 changed the title Refactor RawJsString's representaion to make JsStrings construction from string literal heap-allocation free Refactor RawJsString's representation to make JsStrings construction from string literal heap-allocation free Jul 23, 2024
@jedel1043 jedel1043 changed the title Refactor RawJsString's representation to make JsStrings construction from string literal heap-allocation free Refactor RawJsString's representation to make JsStrings construction from string literal heap-allocation free Jul 23, 2024
@jedel1043 jedel1043 requested a review from a team July 24, 2024 20:34
@jedel1043 jedel1043 added performance Performance related changes and issues Internal Category for changelog labels Jul 24, 2024
@jedel1043 jedel1043 added this to the next-release milestone Jul 24, 2024
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

This is looking fantastic overall! Thanks for all the effort you put into this!

I still want to play around with it a bit more in depth, but thought I'd leave a couple comments.

core/string/src/lib.rs Show resolved Hide resolved
core/string/src/tests.rs Show resolved Hide resolved
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Implementation wise looks perfect! I just have some suggestions around some safety comments that could be improved.

core/string/src/lib.rs Outdated Show resolved Hide resolved
core/string/src/lib.rs Show resolved Hide resolved
core/string/src/lib.rs Outdated Show resolved Hide resolved
core/string/src/lib.rs Outdated Show resolved Hide resolved
core/string/src/lib.rs Outdated Show resolved Hide resolved
@CrazyboyQCD
Copy link
Contributor Author

@jedel1043 , I've improved the comment, if you don't think it's good enough, please continue to point it out.

Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Overall, this PR looks fantastic. Great work on this!

I saw the test added, but I still find myself wishing there were more tests. I'm not entirely sure that's not necessary to merge, imo. Maybe it would be a good follow up or first issue for someone? The docs improvements are also really nice as well.

As a separate note, @jedel1043 this may be a good candidate to build out design docs for per #3938.

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Looks perfect to me!

@nekevss Yeah, I'll open an issue for general improvements around documenting the current design of JsString.

@jedel1043 jedel1043 added this pull request to the merge queue Aug 11, 2024
Merged via the queue into boa-dev:main with commit ddc8b42 Aug 12, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal Category for changelog performance Performance related changes and issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants