Skip to content

Conversation

@pavelsavara
Copy link
Member

inlines calls to dotnetAssert.fastCheck so that we don't format the string or allocate the closure in non-failing cases.

-dotnetAssert.fastCheck(Number.isSafeInteger(value), () => `Value is not an integer: ${value} (${typeof (value)})`);
+if (!(Number.isSafeInteger(value))) throw new Error(`Assert failed: Value is not an integer: ${value} (${typeof (value)})`); // inlined fastCheck

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jan 5, 2026
@pavelsavara pavelsavara self-assigned this Jan 5, 2026
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm labels Jan 5, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara marked this pull request as ready for review January 5, 2026 15:19
Copilot AI review requested due to automatic review settings January 5, 2026 15:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes performance by inlining calls to dotnetAssert.fastCheck during the build process, eliminating unnecessary string formatting and closure allocation in non-failing cases. A new fastCheck function is introduced that accepts a message factory closure, and a Rollup plugin performs regex-based transformations to inline these calls into direct conditional throws.

Key Changes

  • Added a new regexReplace Rollup plugin to perform regex-based code transformations during the build
  • Introduced fastCheck function that accepts a closure for lazy message evaluation, with patterns defined to inline it during build
  • Updated the loader exports table to include fastCheck, incrementing all subsequent indices appropriately

Reviewed changes

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

Show a summary per file
File Description
src/native/rollup.config.plugins.js Added new regexReplace plugin using MagicString for code transformations; updated iife2fe to preserve character positions with whitespace
src/native/rollup.config.defines.js Defined regex patterns to match and inline dotnetAssert.fastCheck calls with both backtick and double-quote message factories
src/native/rollup.config.js Integrated the regexReplace plugin with inlinefastCheck patterns into the build pipeline
src/native/corehost/browserhost/loader/logging.ts Introduced new fastCheck function that takes a message factory closure for lazy evaluation; kept existing check function for backward compatibility
src/native/libs/Common/JavaScript/types/exchange.ts Added fastCheck to type definitions for AssertType and LoaderExportsTable
src/native/libs/Common/JavaScript/cross-module/index.ts Updated table indices to account for the new fastCheck entry at position 5, shifting all loader exports forward by one
src/native/corehost/browserhost/loader/index.ts Added fastCheck to exports and populated it in the loader exports table at the correct index
src/native/libs/System.Native.Browser/utils/memory.ts Converted existing dotnetAssert.check calls to dotnetAssert.fastCheck with arrow functions for performance-sensitive validation code

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
# Conflicts:
#	src/native/rollup.config.js
#	src/native/rollup.config.plugins.js
Copy link
Member

@radekdoulik radekdoulik left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM

As a follow up, it would be great to have a test for that to make sure that the asserts work. Possibly in WBT?

@pavelsavara pavelsavara merged commit a9687b6 into dotnet:main Jan 6, 2026
160 of 164 checks passed
@pavelsavara pavelsavara deleted the inline_asserts branch January 6, 2026 18:30
@pavelsavara
Copy link
Member Author

As a follow up, it would be great to have a test for that to make sure that the asserts work. Possibly in WBT?

I think you are asking for JS/TS only unit tests, rather than integration tests.

I will start thinking about it in #122934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Host os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants