From e71ad6a0b43f309d7aa20f08a6def9421fd41445 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 8 Dec 2025 14:08:46 +0100 Subject: [PATCH] Update main-custom to latest upstream version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibca337dd7a7f37ee4857c85fccd917b47aa3c9d5 Reviewed-on: https://chromium-review.googlesource.com/c/external/github.com/WebKit/JetStream/+/7232297 Reviewed-by: Marja Hölttä --- JetStream.css | 630 -------------------------------- JetStream3Logo.svg | 14 - JetStreamDriver.js | 56 +-- clouds.svg | 15 - generators/async-file-system.js | 4 +- generators/sync-file-system.js | 4 +- jetstreams.svg | 46 --- transformersjs/benchmark.js | 15 +- 8 files changed, 43 insertions(+), 741 deletions(-) delete mode 100644 JetStream.css delete mode 100644 JetStream3Logo.svg delete mode 100644 clouds.svg delete mode 100644 jetstreams.svg diff --git a/JetStream.css b/JetStream.css deleted file mode 100644 index 2ffba2d..0000000 --- a/JetStream.css +++ /dev/null @@ -1,630 +0,0 @@ -/* - * Copyright (C) 2018-2022 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. -*/ - -:root { - --color-primary: #34AADC; - --color-secondary: #86D9FF; - --text-color-inverse: white; - --text-color-primary: black; - --text-color-secondary: #555555; - --text-color-tertiary: #444444; - --text-color-subtle: #6c6c71; - --text-color-very-subtle: #8E8E93; - --heading-color: #2C98D1; - --link-hover-color: #0086BF; - --button-color-primary: rgb(52, 170, 220); - --error-text-color: #d24a59; - --benchmark-heading-color: rgb(183, 183, 183); - --benchmark-error-text-color: #ff8686; - --benchmark-done-result-color: #4A4A4A; - --gap: 3rem; - --width: 200px; -} - -html, -svg text { - font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif; - font-size: 62.5%; - font-synthesis: none; - height: 100vh; -} - -body { - display: flex; - flex-direction: column; - gap: var(--gap); - margin: 0; - font-size: 1.6rem; - font-weight: 400; - line-height: 1.4; - background-repeat: no-repeat; - background-position: center -5vw; - background-size: 100vw; - padding-bottom: 0px; - background-image: url('clouds.svg'); - overflow-y: hidden; - height: 100%; -} - -table { - border-spacing: 0; -} - -body.nonDefaultParams { - filter: hue-rotate(152deg); -} - -.nonDefaultParams .summary { - display: none; -} - -#non-default-params { - display: none; - text-align: center; - - & h2 { - text-align: center; - } - - & p { - text-align: center; - } -} - -.nonDefaultParams #non-default-params { - display: block; -} - -#non-standard-params-table { - border-collapse: collapse; - text-align: left; - display: inline-block; - margin-top: var(--gap); -} - -#non-standard-params-table tr { - padding: 2px; -} - -#non-standard-params-table thead th { - border-bottom: 1px solid var(--foreground); -} - -#non-standard-params-table tbody td { - font-weight: normal; - text-align: left; -} - -#non-standard-params-table thead th, -#non-standard-params-table tbody td { - padding: 0.1em 0.3em; -} -#non-standard-params-table tbody td:nth-child(2) { - color: var(--highlight); -} - - -.overflow-scroll { - overflow-y: auto; -} - -.overflow-visible { - overflow: visible; -} - - -::selection { - background-color: var(--color-primary); - color: var(--text-color-inverse); -} - -main { - display: flex; - flex-direction: column; - gap: var(--gap); - margin: 0 auto; - padding: 0 var(--gap); - max-width: 1180px; - text-align: center; - flex: 1; - overflow: hidden; -} - -main p { - margin: 0; -} - -img { - -webkit-user-drag: none; - user-select: none; -} - -.logo { - box-sizing: border-box; - width: 100%; - user-select: none; - perspective: 600; -} - -.logo .logo-image { - display: block; - box-sizing: border-box; - background-repeat: no-repeat; - background-position: center; - background-image: url('JetStream3Logo.svg'); - color: transparent; - animation: swingin 350ms ease-out forwards; - will-change: transform, opacity; - height: 75px; -} - -#jetstreams { - background-image: url('jetstreams.svg'); - background-repeat: no-repeat; - background-size: contain; - background-position: center; - padding: 2rem 0; - margin: -2rem 0; -} - -#jetstreams svg { - width: 100%; - max-height: 120px; -} - -#magic { - position: absolute; - top: -900px; - left: -900px; - width: 300px; - height: 300px; - display: none; -} - -.summary { - text-align: center; -} - -.summary:empty { - display: none; -} - -article, -.summary { - max-width: 70rem; - margin: 0 auto 0 auto; - opacity: 0; - animation: fadein 0.5s ease-in-out forwards; - animation-delay: 200ms; -} - -article { - display: flex; - flex-direction: column; - gap: var(--gap); -} -h1 { - color: var(--text-color-primary); - text-align: center; - margin-bottom: 0; -} - - -h2, -h3, -h4, -h5, -h6 { - color: var(--heading-color); - text-align: left; -} - - -h4, -h5, -h6 { - margin-bottom: 0; -} - -p { - text-align: left; - color: var(--text-color-secondary); -} - -h5, -h6 { - font-size: 1.6rem; -} - -h6 { - color: var(--text-color-tertiary); -} - -dt { - margin-top: 10px; - font-weight: bold; - text-align: left; -} - -dd { - text-align: left; - padding: 10px 20px; - margin: 0; -} - -a:link, -a:visited { - color: var(--color-primary); -} - -a:hover, -a:active { - color: var(--link-hover-color); -} - -#status label, -a.button { - display: inline-block; - font-weight: 500; - text-decoration: none; - font-size: 2rem; - background-color: var(--button-color-primary); - background-image: linear-gradient(180deg, rgba(134, 217, 255, 1) -80%, rgb(52, 170, 220) 100%); - color: var(--text-color-inverse); - border: 1px solid var(--button-color-primary); - border-radius: 2px; - padding: 0.3rem 0.3rem 0.5rem; - text-align: center; - width: var(--width); - -webkit-touch-callout: none; - user-select: none; -} - -a.button { - animation: fadein 500ms ease-in forwards, scaledown 500ms ease-in forwards; - opacity: 0; -} - -#status label, -.button:hover { - background-image: none; -} - -#status.loading { - position: absolute; - top: 0; - left: 0; - margin: 48vh 0 0; - width: 100%; - line-height: 1.2; - font-size: 4rem; - font-style: italic; - font-weight: 500; - letter-spacing: -0.10rem; - color: transparent; - background-image: linear-gradient(132deg, #96E5FF 0%, #96E5FF 2%, #86D9FF 42%, #8BDAFF 84%, #96E5FF 98%, #96E5FF 100%); - -webkit-background-clip: text; - background-repeat: no-repeat; - -webkit-touch-callout: none; - user-select: none; -} - -#status.error { - max-width: 70rem; - margin: 0 auto 1rem; -} - -.error h2, -.error p { - color: var(--error-text-color); - margin-bottom: 0; - text-align: center; - font-weight: 500; -} - -.error h2 { - font-size: 5rem; - letter-spacing: -0.1rem; - line-height: 1; -} - -#result-summary:empty { - display: none; -} - -#result-summary { - margin-top: 20px; -} - -#result-summary label { - color: var(--text-color-subtle); -} - -#result-summary .score { - font-weight: bold; - font-size: 4rem; - line-height: 1; - color: var(--color-primary); - font-weight: 500; -} - -.benchmark .plot svg { - display: inline-block; - vertical-align: middle; -} - -#result-summary .score .interval { - display: block; - font-weight: normal; -} - -#results { - display: flex; - flex-wrap: wrap; - justify-content: space-around; - gap: var(--gap); - margin: 0 calc(var(--gap) * -1) 0 calc(-var(--gap) * -1); - animation: fadein 500ms ease-out forwards; - opacity: 0; - overflow-y: auto; - flex: 1; - padding-bottom: var(--gap); - box-sizing: border-box; -} - -.benchmark { - position: relative; - flex: 1; - max-width: 20%; - min-width: var(--width); - text-align: left; - color: var(--text-color-very-subtle); - font-size: 1.6rem; - scroll-margin-top: 20vh; - scroll-margin-bottom: 20vh; -} - -.benchmark .result.detail { - display: none; -} -.details .benchmark .result.detail { - display: inline-block; -} - -.benchmark h4, -.benchmark .result, -.benchmark label, -.benchmark .plot { - color: transparent; - background: linear-gradient(160deg, rgba(249, 249, 249, 1) 0%, rgba(238, 238, 238, 1) 100%); - border-radius: 3px; -} - -.benchmark h3 { - color: var(--benchmark-heading-color); -} - -.benchmark-running h4, -.benchmark-running .result, -.benchmark-running label, -.benchmark-running .plot { - color: var(--color-secondary); - background-color: var(--color-secondary); - background-image: none; -} - - -.benchmark-done h3, -.benchmark-done h4, -.benchmark-done .result, -.benchmark-done label, -.benchmark-done .plot { - background-color: transparent; - background-image: none; - -webkit-touch-callout: revert; - user-select: text; -} - -.benchmark-error h4, -.benchmark-error .result, -.benchmark-error label, -.benchmark-error .plot { - color: var(--benchmark-error-text-color); - background-color: var(--benchmark-error-text-color); - background-image: none; -} - -.benchmark-error h3 { - color: var(--benchmark-error-text-color); -} - -.benchmark h3 { - font-weight: 400; - font-size: 1.6rem; - margin: 0; -} - -.benchmark-running h3 { - background-color: transparent; - background-image: none; - color: var(--color-primary); -} - -.benchmark-done h3 { - color: var(--text-color-subtle); -} - -.benchmark a.info { - display: inline-block; - width: 1.5rem; - height: 1.5rem; - border-radius: 100%; - background-color: var(--benchmark-heading-color); - color: var(--text-color-inverse) !important; - user-select: none; - text-align: center; - vertical-align: middle; - font-style: italic; - font-weight: bold; - font-family: 'Times New Roman', Times, serif; - line-height: 1.6rem; - margin-top: -0.2rem; - -} - -.benchmark-running a.info { - background-color: var(--color-primary); -} - -.benchmark-done a.info { - background-color: var(--text-color-subtle); -} - -.benchmark h3 a, -.benchmark h3 a:link, -.benchmark h3 a:active, -.benchmark h3 a:hover, -.benchmark h3 a:visited { - color: inherit; - text-decoration: none; -} - -.benchmark-done h3 a:hover { - color: var(--color-primary); - text-decoration: underline; -} - -.benchmark h4 { - margin: 0.3rem 0; - line-height: 1; - font-weight: 400; - font-size: 2.4rem; -} - -.benchmark-done h4 { - color: var(--color-primary); - background-color: none; -} - -.benchmark p, -.benchmark-done p { - margin: 0; -} - -.benchmark .result { - display: inline-block; - margin-right: 1.6rem; - line-height: 1.3; - font-size: 1.3rem; - font-weight: bold; -} - -#result-summary .benchmark { - text-align: center; - max-width: 100%; - margin: 0; - margin-left: 1.6rem; -} - -.benchmark-done .result { - color: var(--benchmark-done-result-color); -} - -.benchmark label { - display: block; -} - -.benchmark-done label { - color: var(--text-color-very-subtle); - font-weight: 400; -} - -dt:target { - background-color: var(--color-secondary); - color: var(--text-color-inverse); - padding-left: 10px; - border-radius: 5px; -} - -.plot svg circle { - fill: var(--color-primary); - opacity: 0.8; -} - -@keyframes fadein { - from { - opacity: 0; - } - - to { - opacity: 1; - } -} - -@keyframes scaledown { - from { - transform: scale(1.3, 1.3); - } - - to { - transform: scale(1, 1); - } -} - -@keyframes shine { - 0% { - background-position: -1200px center; - } - - 100% { - background-position: 100vw center; - } -} - -@keyframes swingin { - from { - opacity: 0; - transform: rotateY(-85deg) translateZ(200px); - } - - to { - opacity: 1; - transform: rotateY(0deg) translateZ(0px); - } -} - -@media (max-width: 415px) { - body { - background-position: center 4rem; - } - - .logo .logo-image { - height: 60px; - } - - #jetstreams { - background-size: 200%; - } -} diff --git a/JetStream3Logo.svg b/JetStream3Logo.svg deleted file mode 100644 index 5f8847b..0000000 --- a/JetStream3Logo.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/JetStreamDriver.js b/JetStreamDriver.js index 61e0806..97e170c 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -560,8 +560,18 @@ const BenchmarkState = Object.freeze({ class Scripts { - constructor() { + constructor(preloads) { this.scripts = []; + + let preloadsCode = ""; + let resourcesCode = ""; + for (let { name, resource, blobURLOrPath } of preloads) { + console.assert(name?.length > 0, "Invalid preload name."); + console.assert(resource?.length > 0, "Invalid preload resource."); + console.assert(blobURLOrPath?.length > 0, "Invalid preload data."); + preloadsCode += `${JSON.stringify(name)}: "${blobURLOrPath}",\n`; + resourcesCode += `${JSON.stringify(resource)}: "${blobURLOrPath}",\n`; + } // Expose a globalThis.JetStream object to the workload. We use // a proxy to prevent prototype access and throw on unknown properties. this.add(` @@ -569,11 +579,16 @@ class Scripts { get(target, property, receiver) { throw new Error(name + "." + property + " is not defined."); } - }); + }); globalThis.JetStream = { __proto__: throwOnAccess("JetStream"), preload: { __proto__: throwOnAccess("JetStream.preload"), + ${preloadsCode} + }, + resources: { + __proto__: throwOnAccess("JetStream.preload"), + ${resourcesCode} }, }; `); @@ -631,8 +646,8 @@ class Scripts { } class ShellScripts extends Scripts { - constructor() { - super(); + constructor(preloads) { + super(preloads); this.prefetchedResources = Object.create(null);; } @@ -698,8 +713,8 @@ class ShellScripts extends Scripts { } class BrowserScripts extends Scripts { - constructor() { - super(); + constructor(preloads) { + super(preloads); this.add("window.onerror = top.currentReject;"); } @@ -738,7 +753,7 @@ class Benchmark { this.isAsync = !!plan.isAsync; this.allowUtf16 = !!plan.allowUtf16; this.scripts = null; - this.preloads = null; + this.preloads = []; this.shellPrefetchedResources = null; this.results = []; this._state = BenchmarkState.READY; @@ -898,7 +913,7 @@ class Benchmark { if (this.isDone) throw new Error(`Cannot run Benchmark ${this.name} twice`); this._state = BenchmarkState.PREPARE; - const scripts = isInBrowser ? new BrowserScripts() : new ShellScripts(); + const scripts = isInBrowser ? new BrowserScripts(this.preloads) : new ShellScripts(this.preloads); if (!!this.plan.deterministicRandom) scripts.addDeterministicRandom() @@ -908,15 +923,6 @@ class Benchmark { if (this.shellPrefetchedResources) { scripts.addPrefetchedResources(this.shellPrefetchedResources); } - if (this.plan.preload) { - let preloadCode = ""; - for (let [ variableName, blobURLOrPath ] of this.preloads) { - console.assert(variableName?.length > 0, "Invalid preload name."); - console.assert(blobURLOrPath?.length > 0, "Invalid preload data."); - preloadCode += `JetStream.preload[${JSON.stringify(variableName)}] = "${blobURLOrPath}";\n`; - } - scripts.add(preloadCode); - } const prerunCode = this.prerunCode; if (prerunCode) @@ -1067,12 +1073,11 @@ class Benchmark { })); if (this.plan.preload) { - this.preloads = []; for (const [name, resource] of Object.entries(this.plan.preload)) { promises.push(this.loadBlob("preload", name, resource).then((blobData) => { if (!globalThis.allIsGood) return; - this.preloads.push([ blobData.prop, blobData.blobURL ]); + this.preloads.push({ name: blobData.prop, resource: blobData.resource, blobURLOrPath: blobData.blobURL }); this.updateCounter(); }).catch((error) => { // We'll try again later in retryPrefetchResourceForBrowser(). Don't throw an error. @@ -1099,7 +1104,7 @@ class Benchmark { if (type == "preload") { if (this.failedPreloads && this.failedPreloads[blobData.prop]) { this.failedPreloads[blobData.prop] = false; - this.preloads.push([ blobData.prop, blobData.blobURL ]); + this.preloads.push({ name: blobData.prop, resource: blobData.resource, blobURLOrPath: blobData.blobURL }); counter.failedPreloadResources--; } } @@ -1112,7 +1117,7 @@ class Benchmark { if (!globalThis.allIsGood) return; if (blobData.type == "preload") - this.preloads.push([ blobData.prop, blobData.blobURL ]); + this.preloads.push({ name: blobData.prop, resource: blobData.resource, blobURLOrPath: blobData.blobURL }); this.updateCounter(); }); @@ -1150,8 +1155,7 @@ class Benchmark { console.assert(this.scripts === null, "This initialization should be called only once."); this.scripts = this.plan.files.map(file => shellFileLoader.load(file)); - console.assert(this.preloads === null, "This initialization should be called only once."); - this.preloads = []; + console.assert(this.preloads.length === 0, "This initialization should be called only once."); this.shellPrefetchedResources = Object.create(null); if (!this.plan.preload) { return; @@ -1170,7 +1174,7 @@ class Benchmark { this.shellPrefetchedResources[resource] = bytes; } - this.preloads.push([name, resource]); + this.preloads.push({ name, resource, blobURLOrPath: resource }); } } @@ -2516,8 +2520,8 @@ let BENCHMARKS = [ inputFontItalic: "./Kotlin-compose/build/jetbrainsmono_italic.ttf", inputFontRegular: "./Kotlin-compose/build/jetbrainsmono_regular.ttf" }, - iterations: 15, - worstCaseCount: 2, + iterations: 5, + worstCaseCount: 1, tags: ["default", "Wasm"], }), new AsyncBenchmark({ diff --git a/clouds.svg b/clouds.svg deleted file mode 100644 index e3c62bc..0000000 --- a/clouds.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/generators/async-file-system.js b/generators/async-file-system.js index 03e146e..1349709 100644 --- a/generators/async-file-system.js +++ b/generators/async-file-system.js @@ -38,12 +38,12 @@ const isLittleEndian = computeIsLittleEndian(); async function *randomFileContents() { let counter = 1; while(true) { - const numBytes = ((counter * 1192.18851371) % 2056); + const numBytes = (((counter * 1192.18851371) | 0) % 2056); counter++; let result = new ArrayBuffer(numBytes); let view = new Uint8Array(result); for (let i = 0; i < numBytes; ++i) - view[i] = (i + counter) % 255; + view[i] = (i + counter) % 256; yield new DataView(result); } } diff --git a/generators/sync-file-system.js b/generators/sync-file-system.js index af65d58..62c1159 100644 --- a/generators/sync-file-system.js +++ b/generators/sync-file-system.js @@ -38,12 +38,12 @@ const isLittleEndian = computeIsLittleEndian(); function *randomFileContents() { let counter = 1; while(true) { - const numBytes = ((counter * 1192.18851371) % 2056); + const numBytes = (((counter * 1192.18851371) | 0) % 2056); counter++; let result = new ArrayBuffer(numBytes); let view = new Uint8Array(result); for (let i = 0; i < numBytes; ++i) - view[i] = (i + counter) % 255; + view[i] = (i + counter) % 256; yield new DataView(result); } }; diff --git a/jetstreams.svg b/jetstreams.svg deleted file mode 100644 index b767e43..0000000 --- a/jetstreams.svg +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/transformersjs/benchmark.js b/transformersjs/benchmark.js index 2c80a5a..4f611f6 100644 --- a/transformersjs/benchmark.js +++ b/transformersjs/benchmark.js @@ -16,13 +16,14 @@ globalThis.URL = URL; // Polyfill fetch for shell-compatibility and to cache / preload model weights etc. let preload = { /* Initialized in init() below due to async. */ }; -const originalFetch = globalThis.fetch ?? function(url) { - throw new Error("no fetch available"); -} -globalThis.fetch = async function(url) { + +async function redirectingFetch(url) { // DEBUG // console.log('fetch', url); + if (url.startsWith("./")) + url = JetStream.resources[url]; + // Redirect some paths to cached/preloaded resources. if (preload[url]) { return { @@ -38,8 +39,7 @@ globalThis.fetch = async function(url) { }; } - // This should only be called in the browser, where fetch() is available. - return originalFetch(url); + throw new Error(`Unexpected resource requested in benchmark: ${url}`); }; // JetStream benchmark harness. Reuse for two different Transformers.js tasks. @@ -66,6 +66,9 @@ class Benchmark { // DEBUG // console.log('inputFile', this.inputFile.byteLength, 'bytes'); } + + // After we have loaded everything close the door behind us to make sure no other network requests happen. + globalThis.fetch = redirectingFetch; } async runIteration() {