') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Reduce string interpolation overhead by pentp · Pull Request #114497 · dotnet/runtime · GitHub
Skip to content

Reduce string interpolation overhead - #114497

Merged
stephentoub merged 3 commits into
dotnet:mainfrom
pentp:null-string-interp
May 28, 2025
Merged

Reduce string interpolation overhead#114497
stephentoub merged 3 commits into
dotnet:mainfrom
pentp:null-string-interp

Conversation

@pentp

Copy link
Copy Markdown
Contributor

For Nullable<T> where T:ISpanFormattable removes a lot of dead code for null values (ToString and AppendLiteral calls).
For reference types removes many redundant null checks and two interface casts (CORINFO_HELP_CHKCASTINTERFACE).

For non-null Nullable<T> the CORINFO_HELP_BOX_NULLABLE allocation still remains - this needs fixing in JIT.

CopilotAI review requested due to automatic review settings April 10, 2025 16:30
@ghostghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 10, 2025

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 10, 2025
@am11am11 added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 10, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@EgorBo

Copy link
Copy Markdown
Member

For non-null Nullable the CORINFO_HELP_BOX_NULLABLE allocation still remains - this needs fixing in JIT.

@pentp is there a minimal repro for it?

@pentp

Copy link
Copy Markdown
ContributorAuthor

For non-null Nullable the CORINFO_HELP_BOX_NULLABLE allocation still remains - this needs fixing in JIT.

@pentp is there a minimal repro for it?

Minimal repro: https://godbolt.org/z/WcnoMG9GK

@EgorBo

Copy link
Copy Markdown
Member

For non-null Nullable the CORINFO_HELP_BOX_NULLABLE allocation still remains - this needs fixing in JIT.

@pentp is there a minimal repro for it?

Minimal repro: https://godbolt.org/z/WcnoMG9GK

@AndyAyersMS looks like something EA could help with?

***** BB02 [0002]
STMT00004 ( 0x00D[E-] ... ??? ) <- INLRT @ 0x000[E-]
[000022] DAC-G------ * STORE_LCL_VAR ref V02 tmp1 [000019] --C-G------ \--* CALL nullcheck ref System.Guid:ToString(System.String,System.IFormatProvider):System.String:this
[000021] --C-G------ this +--* ADD byref [000015] --C-G------ | +--* CALL help ref CORINFO_HELP_BOX_NULLABLE
[000013] H---------- arg0 | | +--* CNS_INT(h) long 0x7ffab4be4648 class System.Nullable`1[System.Guid]
[000014] ----------- arg1 | | \--* LCL_ADDR byref V00 arg0 [+0]
[000020] ----------- | \--* CNS_INT long 8
[000017] ----------- arg1 +--* CNS_INT ref null
[000018] ----------- arg2 \--* CNS_INT ref null

@AndyAyersMS

Copy link
Copy Markdown
Member

@AndyAyersMS looks like something EA could help with?

If we expand CORINFO_HELP_BOX_NULLABLE inline then perhaps... or we could try and handle it as an allocator and then inline expand it when it does not escape. That would require spilling the result of the helper call to a temp in the importer.

@stephentoub

Copy link
Copy Markdown
Member

/ba-g failures are unrelated

@stephentoub
stephentoub merged commit 3d1af41 into dotnet:mainMay 28, 2025
@pentp
pentp deleted the null-string-interp branch May 29, 2025 07:58
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jun 28, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtimecommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@pentp@EgorBo@AndyAyersMS@stephentoub@am11