Skip to content

[fork twin] Performance: keep the time origin per environment - #25

Open
matthargett wants to merge 6 commits into
mainfrom
performance-per-env-time-origin
Open

matthargett wants to merge 6 commits into
mainfrom
performance-per-env-time-origin

Conversation

@matthargett

Copy link
Copy Markdown
Member

Fork CI twin of BabylonJS#240.

performance.now() measured from a single process-wide start time that every Performance::Initialize rewrote. Any host that runs more than one AppRuntime (a second runtime, or a worker) therefore moves the first realm's clock backwards on each initialization, and with concurrent runtimes the write is a data race (ThreadSanitizer reports it once workers exist).

Each realm has its own time origin on the web, so capture it per environment in the now() closure, and measure with steady_clock, which cannot step.

Verified on macOS (JavaScriptCore): full UnitTests green. Fork twin: rebeckerspecialties/JsRuntimeHost#TWIN.

performance.now() measured from one process-wide start time that every
Initialize() rewrote. With Workers each runtime initializes the polyfill
on its own thread, so ThreadSanitizer reports the write race, and every
new worker also moved the main realm's clock backwards. Capture the
origin per environment in the now() closure, as each realm has its own
time origin on the web, and use steady_clock, which cannot step.

(cherry picked from commit 2391b0d)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T10:55:50.425063Z 1ff5263 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

matthargett and others added 5 commits September 14, 2026 07:04
Two runtimes: after the second initializes the polyfill, the first
one's performance.now() must not go backwards. Fails against the
process-wide origin (the second Initialize reset it to zero).
## Summary

Follow-up to
BabylonJS#230 (comment).

The UTF-16 decoder previously dropped a trailing odd byte and created
JavaScript strings from unpaired surrogates. Replacement mode in the
Encoding Standard requires U+FFFD for both, in either endianness.

`DecodeUtf16` now:

- emits U+FFFD for a leftover odd byte
- emits U+FFFD for a lone lead or trail surrogate
- treats a lead followed by a non-trail as one replacement, then
reprocesses the second unit
- treats an unpaired lead plus a leftover odd byte as a single
end-of-queue replacement

The README describes this behavior and the still-unsupported `fatal`
option.

## Timer cleanup after rebase

Correction to the original description, per [Gary's
review](BabylonJS#235 (review)):
`Dispatch` always passed `0`, so the `id == 0` branch was **always
taken**. The **nonzero ID-reuse path** was dead.

The latest `main` already includes the timer refactor from
BabylonJS#232, which removes
`DispatchImpl` and guards against duplicate-ID insertion. The rebase
keeps that implementation unchanged and drops this PR's superseded timer
changes. The remaining diff contains only TextDecoder, its
documentation, and the UTF-16 regression cases.

## Regression coverage

- Trailing odd byte, both endiannesses
- Lone lead / lone trail, both endiannesses
- Lead + BMP (`U+D800` then `'A'`) produces `"\uFFFDA"`
- Lead + leftover odd byte produces a single `"\uFFFD"`

Existing valid-pair and BOM cases are unchanged.

---------

Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da74bc94-a7dc-4817-bd81-59b5c6b123fc
## Context

`build-linux.yml` set job-level `CC`/`CXX` env alongside the `-D
CMAKE_C_COMPILER` / `-D CMAKE_CXX_COMPILER` configure flags. The `-D`
flags already select the compiler for both the gcc and clang matrix
legs, so the env block was redundant.

No behavior change: on the parallel UrlLib CI cleanup both the gcc and
clang Linux jobs stayed green with the env removed. The Run Tests step's
`env` (`TSAN_OPTIONS` / `JSC_useConcurrentGC`) is untouched.

Part of a small cross-repo consistency pass — UrlLib landed the same
cleanup. BabylonNative was checked and intentionally left alone: its
`build-linux.yml` env is load-bearing there (its configure passes no
`-D` compiler flags).

[Created by Copilot on behalf of @bghgary]

Co-authored-by: Gary Hsu <223556219+Copilot@users.noreply.github.com>
[Created by Copilot on behalf of @bghgary]

Native and JavaScript runtime tests for unrelated features were grouped
together, making coverage hard to navigate. This change groups the
existing tests by feature and packages the generated test bundle and
fixtures together under `Assets`. The same tests continue to run through
the existing runner.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…abylonJS#257)

Performance.TimeOriginIsPerEnvironment moves from Shared.cpp to Source/Tests.Performance.cpp,
registered in the desktop and Android test targets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants