-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src: use simdutf for converting externalized builtins to UTF-16 #46119
Merged
nodejs-github-bot
merged 3 commits into
nodejs:main
from
addaleax:simdutf-for-builtin-conversions
Jan 10, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "env-inl.h" | ||
#include "node_external_reference.h" | ||
#include "node_internals.h" | ||
#include "simdutf.h" | ||
#include "util-inl.h" | ||
|
||
namespace node { | ||
|
@@ -35,7 +36,6 @@ BuiltinLoader BuiltinLoader::instance_; | |
|
||
BuiltinLoader::BuiltinLoader() : config_(GetConfig()), has_code_cache_(false) { | ||
LoadJavaScriptSource(); | ||
#if defined(NODE_HAVE_I18N_SUPPORT) | ||
#ifdef NODE_SHARED_BUILTIN_CJS_MODULE_LEXER_LEXER_PATH | ||
AddExternalizedBuiltin( | ||
"internal/deps/cjs-module-lexer/lexer", | ||
|
@@ -52,7 +52,6 @@ BuiltinLoader::BuiltinLoader() : config_(GetConfig()), has_code_cache_(false) { | |
AddExternalizedBuiltin("internal/deps/undici/undici", | ||
STRINGIFY(NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH)); | ||
#endif // NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH | ||
#endif // NODE_HAVE_I18N_SUPPORT | ||
} | ||
|
||
BuiltinLoader* BuiltinLoader::GetInstance() { | ||
|
@@ -240,7 +239,6 @@ MaybeLocal<String> BuiltinLoader::LoadBuiltinSource(Isolate* isolate, | |
#endif // NODE_BUILTIN_MODULES_PATH | ||
} | ||
|
||
#if defined(NODE_HAVE_I18N_SUPPORT) | ||
void BuiltinLoader::AddExternalizedBuiltin(const char* id, | ||
const char* filename) { | ||
std::string source; | ||
|
@@ -252,16 +250,20 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id, | |
return; | ||
} | ||
|
||
icu::UnicodeString utf16 = icu::UnicodeString::fromUTF8( | ||
icu::StringPiece(source.data(), source.length())); | ||
auto source_utf16 = std::make_unique<icu::UnicodeString>(utf16); | ||
Add(id, | ||
UnionBytes(reinterpret_cast<const uint16_t*>((*source_utf16).getBuffer()), | ||
utf16.length())); | ||
// keep source bytes for builtin alive while BuiltinLoader exists | ||
GetInstance()->externalized_source_bytes_.push_back(std::move(source_utf16)); | ||
Add(id, source); | ||
} | ||
|
||
bool BuiltinLoader::Add(const char* id, std::string_view utf8source) { | ||
size_t expected_u16_length = | ||
simdutf::utf16_length_from_utf8(utf8source.data(), utf8source.length()); | ||
auto out = std::make_shared<std::vector<uint16_t>>(expected_u16_length); | ||
size_t u16_length = simdutf::convert_utf8_to_utf16le( | ||
utf8source.data(), | ||
utf8source.length(), | ||
reinterpret_cast<char16_t*>(out->data())); | ||
out->resize(u16_length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this bit really necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of alternative would you suggest? Or is this about the |
||
return Add(id, UnionBytes(out)); | ||
} | ||
#endif // NODE_HAVE_I18N_SUPPORT | ||
|
||
// Returns Local<Function> of the compiled module if return_code_cache | ||
// is false (we are only compiling the function). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can just create a
UnionBytes
constructor that takes astd::string_view
that does this? (then I guess thatUnionBytes
can own the vector?))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,
UnionBytes
that supports storing UTF-8 directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, I’ll merge this in order to unblock #45942, but I’m still happy to iterate further here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A union for everything ;)