Problems and future plans on token system
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 1k
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của otakustay/react-diff-view
-
pinned
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
otakustay/react-diff-view#101 · 5 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
otakustay/react-diff-view#238 · 1 bình luận ·
-
Virtualization for diffsĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
otakustay/react-diff-view#237 ·
-
跨行注释未闭合时的代码被高亮为注释了Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
otakustay/react-diff-view#233 · 2 bình luận ·
-
Accessibility: Add screenreader-only text to table cells for status indicatorsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
otakustay/react-diff-view#232 · 1 bình luận ·
Tất cả issue của otakustay/react-diff-view
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vercel/streamdown#673 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(stream-protocol): document messageMetatadata on start/finish and the message-metadata chunkCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởfactory-active task-identify-harness-labels-done task-identify-issue-type-done
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vercel/ai#23375 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
agilepathway/label-checker#721 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CLI Empathy needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
chromaui/chromatic-cli#1524 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày