Problems and future plans on token system
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
- Tipo di issue
- Refactoring
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
- Ambito
- frontend, performance
Direzione di ricerca
Start with the linked token system documentation and the mentioned files: src/tokenize/utils.js, normalizeToLines.js, pickRanges.js, and backToTree.js. Review the proposed clone, path, and node-shape changes and their breaking-change implications; this issue is complete only after a concrete migration plan and agreed implementation scope are defined.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Token system is a key feature of react-diff-view and is the source of its powerfulness.
I looked into current implementation of token system recently and discovered some vulnerabilities about it, mostly about performance.
Too many clones
To ensure token system works safely by default, we introduce a clone function to copy an entire path, that is clone every node inside this path. This function is used in almost every key functions like normalizeToLines and other manipulation utilities.
Actually, while we guarantee that token node is immutable, we can get rid of all these clones, boosting performance considerably.
In current situation we don't have a statement saying "you cannot mutate token node" and removing clone operations can introduce some potential breaking changes, but I think it should be safe in most cases.
Too many slices
Previously we represent a path as an array of token nodes, the last node in this array is always a text node:
[
{type: 'element'},
{type: 'element'},
{type: 'mark'},
{type: 'text', value: 'Hello World'}
]
In nearly all cases when we need to manipulate this path, we were not changing the text, we frequently insert a node before text node, the implement could be:
const parents = path.slice(0, -1);
const text = path[path.length - 1];
const newPath = [...parents, customNode, text];
We notice a .slice(0, -1) inside this code which can cause some dropdown on performance.
To optimize this, we can separate node path and its containing text into a tuple like:
[
[
{type: 'element'},
{type: 'element'},
{type: 'mark'},
],
'Hello World'
]
We can insert a node before text more efficiently:
const [parents, text] = path;
const newPath = [[...parents, customNode], text];
In this solution we also unwrap text node into a single string to reduce the creation and garbage collection of node objects.
This is a breaking change since any custom enhancers written previously will fail to work on the new data structure.
Too dynamic nodes
For the lifetime of react-diff-view, we didn't have a strictly defined type for token node, that is, users can put any properties into a node and use them in custom renderToken function.
This is easy to use, but a dynamic node causes more than expected node clones and a poor performance node merge algorithm.
We decide to later define the node more strictly, leaving only type and a dynamic properties for it, the clone and compare can be much simpler:
const cloneNode = node => {
return {
type: node.type,
properties: node.properties,
}
};
const areNodesEquals = (x, y) => (x.type === y.type && shallowEquals(x.properties, y.properties));
This is also a breaking change since a more strict structure is forced.
Reuse token system
As a result of performance inspection and reusability consideration, I developed a tiny library source-tokenizer to handle these, on the initial implement we get about 25% performance boost:
highlighting a json file with 11029 lines, 10 times
legacy: 22.384s
current: 16.038s
I'm preparing to develop a react-source-view component based on this library to render source codes, react-diff-view which focused on render diff contents will have a major version to use this library in 2020, an upgrade guide will be published then.
- Lingua principale
- TypeScript
- Stelle
- 1k
- Fork
- 88
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
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 otakustay/react-diff-view
-
pinned
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
otakustay/react-diff-view#101 · 5 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
otakustay/react-diff-view#238 · 1 commento ·
-
Virtualization for diffsAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
otakustay/react-diff-view#237 ·
-
跨行注释未闭合时的代码被高亮为注释了Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
otakustay/react-diff-view#233 · 2 commenti ·
-
Accessibility: Add screenreader-only text to table cells for status indicatorsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
otakustay/react-diff-view#232 · 1 commento ·
Tutte le issue di otakustay/react-diff-view
Issue simili
-
useFragment does not require `variables` when the fragment's variables type has required fieldsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apollographql/apollo-client#13493 ·
I maintainer di solito rispondono entro 1 giorno
-
Custom hosts written as trailing-dot FQDNs (`host.local.`) aren't detected as local backendsForse già presa @roboomp l’ha presa oggi. Apertabug prio:p2 providers triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
can1357/oh-my-pi#15798 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
code-yeongyu/oh-my-openagent#10172 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
PDFCraftTool/pdfcraft#189 ·
-
Add the Yahoo chart API duplicate last-day row (yfinance#573) to incidents.md (about 1 hour)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertadata docs good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
pacocartones/market-data-sanity-checker#160 ·
I maintainer di solito rispondono entro 1 giorno