Can we allow JS functions to opt-in to be prempted?
An expensive synchronous function will jank the UI:
function expensive() {}
async function findIndexAsync(promises, predicate) { | |
let i = 0; | |
for await (const p of asyncIterate(promises)) { | |
if (predicate(p)) { | |
return i; | |
} | |
i++; | |
} | |
} |
export const a = 'hello'; | |
export const f = (a: any, b: any, c: any) => { | |
return { | |
a, b, c | |
}; | |
}; |
import {LitElement, html} from 'lit-element'; | |
import {UseWindowSize} from './useWindowSize.js'; | |
class extends UseWindowSize()(LitElement) { | |
render() { | |
return html` | |
<p> | |
width: ${window.innerWidth} | |
height: ${window.innerHeight} | |
</p> |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Text data vs nodeValue #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
import lottie from './lib/lottie-import.js'; | |
export class LottiePlayerElement extends HTMLElement { | |
get src(): string | null { | |
return this.getAttribute('src'); | |
} | |
set src(v: string | null) { | |
if (v == null) { |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Directive Implementations</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Creating an TreeWalker, DOM element, and setting a walker's currentNode #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
This is a reproduction for https://bugs.chromium.org/p/chromium/issues/detail?id=1050221
To reproduce:
npm i
npm start
Chrome will start, cycle through some async tasks, and print the duration to the document and the terminal running node. On my laptop it takes ~500ms.
Next, run npm start
again, bug switch back to the terminal as soon as Chrome launches. There should be enough time to put Chrome in the background before the task completes. The tasks should either never start or never complete. If you put Chrome in the foreground, the tasks will finish quickly.
Modules may need to load non-JS resources that would clearly categorized as dependencies - the module is not truly ready until those resources are (example: templates for UI components). Loading APIs, like fetch()
are asynchronous, and there is currently no way to make a module wait for asynchronous calls.
Top-level await, which would block execution within a module on a await expression, has been proposed as a way to solve this problem. It has a critical problem as highlighted here by Rich Harris.