parseAttribute: every plain-text attribute throws inside isJSON, which is slow when rendering on the server
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, node.js
- Lĩnh vực
- performance
Hướng nghiên cứu
Công việc nằm ở parseAttribute và hàm hỗ trợ isJSON, hàm này gọi JSON.parse trong try/catch cho mỗi giá trị, cùng với isNumber, hàm này tạo lại RegExp mỗi lần được gọi. Hãy bắt đầu bằng việc đọc ba hàm này và các test hiện có bao phủ parseAttribute. Hoàn thành khi các giá trị không phải JSON trả về mà không ném ngoại lệ, các giá trị JSON được phân tích đúng một lần, và các test hiện có vẫn chạy thành công mà không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- JavaScript
- Star
- 30
- Fork
- 5
- Merge trung bình
- 1 giờ 57 phút
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 webtides/element-js
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
webtides/element-js#198 ·
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 84/100
webtides/element-js#194 · 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 82/100
webtides/element-js#193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it tooCó thể đã có người làm @eddyloewen đã nhận 28 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
webtides/element-js#185 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[RENDERER]: a line break at the start of a <textarea> differs between toString() and a client renderĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
webtides/element-js#200 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của webtides/element-js
Issue tương tự
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Độ 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
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Agent360dk/browser-mcp#124 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area:site feature good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
pacocartones/free-llm-api-hub#829 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ 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
-
bug
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
Jason-Vaughan/TangleClaw#3270 ·
Maintainer thường phản hồi trong vòng 1 ngày