parseAttribute: every plain-text attribute throws inside isJSON, which is slow when rendering on the server
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
- Ambito
- performance
Direzione di ricerca
Il lavoro riguarda parseAttribute e la sua funzione di supporto isJSON, che chiama JSON.parse dentro try/catch per ogni valore, più isNumber, che ricostruisce il proprio RegExp a ogni chiamata. Inizia leggendo queste tre funzioni e i test esistenti che coprono parseAttribute. È completato quando i valori non JSON vengono restituiti senza lanciare eccezioni, i valori JSON vengono analizzati una sola volta e i test esistenti passano invariati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Goal
Reading an attribute that is plain text (a class, a label, an address) costs no thrown exception, on the server as in the browser.
Context
parseAttribute asks isJSON(value) first, and isJSON is try { return JSON.parse(value) && !!value } catch { return false }. Most attribute values are plain text, so most calls throw: the engine builds a SyntaxError with its stack each time, and a value that is JSON is parsed twice, once to test and once to read. isNumber builds its RegExp anew on every call as well.
In the browser this runs once per element at upgrade and nobody notices. With element-js-ssr-renderer it runs for every attribute of every instance on every request, deep inside the recursion of the render, where a stack is long. In a CPU profile of a form page with a few dozen elements parseAttribute was the largest single function, about a seventh of the whole request. On a runtime that limits CPU per request (Cloudflare Workers) that decides whether a page fits.
Acceptance criteria
- A value that cannot be JSON is returned without an exception being thrown
- A value that is JSON is parsed once
-
parseAttributereturns for every value what it returns today; the existing tests pass unchanged
Proposal (non-binding)
Look at the value before parsing it: true, false and null by comparison; JSON.parse only where the first character can open JSON ({, [, ", -, a digit), with its result kept instead of parsed again; the number pattern as a constant.
Out of scope
- What a boolean attribute without a value reads as (#199)
- Lingua principale
- JavaScript
- Stelle
- 30
- Fork
- 5
- Merge medio
- 1h 57m
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di webtides/element-js
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
webtides/element-js#198 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
webtides/element-js#194 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
webtides/element-js#193 ·
I maintainer di solito rispondono entro 1 giorno
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it tooForse già presa @eddyloewen l’ha presa 28 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
webtides/element-js#185 ·
I maintainer di solito rispondono entro 1 giorno
-
[RENDERER]: a line break at the start of a <textarea> differs between toString() and a client renderAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
webtides/element-js#200 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di webtides/element-js
Issue simili
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Agent360dk/browser-mcp#124 ·
I maintainer di solito rispondono entro 2 giorni
-
area:site feature good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pacocartones/free-llm-api-hub#829 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
Jason-Vaughan/TangleClaw#3270 ·
I maintainer di solito rispondono entro 1 giorno