-
Notifications
You must be signed in to change notification settings - Fork 44
CachedTypes: stop encoding source text into CachedSourceCodeKey #186
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1644,12 +1644,49 @@ class CachedStringSourceProvider : public CachedSourceProviderShape<StringSource | |
| void encode(Encoder& encoder, const StringSourceProvider& sourceProvider) | ||
| { | ||
| Base::encode(encoder, sourceProvider); | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| // SourceCodeKey::operator== under BUN_JSC_ADDITIONS does not compare source | ||
| // text, so encoding it here only wastes ~source_size bytes of bytecode and | ||
| // forces a ~source_size heap allocation at decode time. Store length only — | ||
| // the comparison still validates length() and host(). | ||
| m_sourceLength = sourceProvider.source().length(); | ||
| #else | ||
| m_source.encode(encoder, sourceProvider.source().toString()); | ||
| #endif | ||
| } | ||
|
|
||
| #if USE(BUN_JSC_ADDITIONS) | ||
| // The caller (CachedSourceProvider::decode) returns SourceProvider*, so the | ||
| // BUN reuse path can return the runtime provider as its base type without | ||
| // any reinterpret_cast through the StringSourceProvider sibling. | ||
| SourceProvider* decode(Decoder& decoder, SourceProviderSourceType sourceType) const | ||
| #else | ||
| StringSourceProvider* decode(Decoder& decoder, SourceProviderSourceType sourceType) const | ||
| #endif | ||
| { | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| // Reuse the runtime SourceProvider the Decoder was constructed with rather | ||
| // than allocating a fresh StringSourceProvider holding a heap copy of the | ||
| // source. The decoded key is only used for SourceCodeKey equality, which | ||
| // under BUN_JSC_ADDITIONS does not look at source bytes. | ||
| // | ||
| // Base::decode is intentionally skipped: the runtime provider already has | ||
| // its sourceURLDirective / sourceMappingURLDirective / sourceTaintedOrigin | ||
| // set, and the decoded key only needs sourceOrigin().url().host() and | ||
| // length() for equality. CachedSourceProviderShape fields are offset-based | ||
| // (not stream-based), so leaving them undecoded does not affect later reads. | ||
| if (RefPtr<SourceProvider> provider = decoder.provider()) { | ||
| if (provider->sourceType() == sourceType && provider->source().length() == m_sourceLength) | ||
| return provider.leakRef(); | ||
| } | ||
| // Fallback for callers that did not supply a provider: decode without source | ||
| // bytes. SourceCodeKey::operator== ignores string(), but length() is compared, | ||
| // so synthesize a provider whose source() is empty — length() will mismatch | ||
| // and the cache entry will be rejected, which is the conservative behaviour. | ||
| String decodedSource; | ||
|
Comment on lines
+1682
to
+1686
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. Don't make key-only decode paths synthesize a zero-length provider. When At minimum, thread 🔧 Minimal fix for the validity-check path bool isCachedBytecodeStillValid(VM& vm, Ref<CachedBytecode> cachedBytecode, const SourceCodeKey& key, SourceCodeType type)
{
auto span = cachedBytecode->span();
if (span.empty())
return false;
auto* cachedEntry = std::bit_cast<const GenericCacheEntry*>(span.data());
- Ref decoder = Decoder::create(vm, WTF::move(cachedBytecode));
+ Ref decoder = Decoder::create(vm, WTF::move(cachedBytecode), &key.source().provider());
return cachedEntry->isStillValid(decoder.get(), key, tagFromSourceCodeType(type));
}🤖 Prompt for AI Agents |
||
| #else | ||
| String decodedSource = m_source.decode(decoder); | ||
| #endif | ||
| SourceOrigin decodedSourceOrigin = m_sourceOrigin.decode(decoder); | ||
| String decodedSourceURL = m_sourceURL.decode(decoder); | ||
| TextPosition decodedStartPosition = m_startPosition.decode(decoder); | ||
|
|
@@ -1660,7 +1697,11 @@ class CachedStringSourceProvider : public CachedSourceProviderShape<StringSource | |
| } | ||
|
|
||
| private: | ||
| #if USE(BUN_JSC_ADDITIONS) | ||
| unsigned m_sourceLength; | ||
| #else | ||
| CachedString m_source; | ||
| #endif | ||
| }; | ||
|
|
||
| #if ENABLE(WEBASSEMBLY) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.