microsoft / microsoft/TypeScript
[Performance] Add option for parser to compute Node.loc eagerly during parsing
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
Suggestion
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
performance, parser, node location, loc
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Currently TS does not compute or store a node's loc during a parse.
For TS itself this is fine because it's rarer that TS needs this information (I don't know for sure, but I'd say it only needs it when reporting errors?).
For @typescript-eslint, however, we need to compute the location because ESLint uses it for various things.
The issue is that computing the loc after the parse cycle means that TS has to do a binary search on the line/range table to compute the line/col of each of the start/end - which is obviously not super cheap to do.
As an alternative approach I tried changing ts-eslint's parser to lazily compute the locaction (https://github.com/typescript-eslint/typescript-eslint/pull/6542). Sadly it was a net-neutral change because (I believe) the cost of defining a getter/setter is much more expensive than a property.
Unfortunately based on the way the ESLint's AST is designed we can't introduce a getLoc function, and can only defer this by using accessors.
Here is a cpu profile to help illustrate the cost - NON_LAZY_1.cpuprofile.zip. If you load this into https://speedscope.app you can use the search to find SourceFileObject.getLineAndCharacterOfPosition. It shows that the total time spent in SourceFileObject.getLineAndCharacterOfPosition for the parse was ~260ms (0.61% of the type-aware lint run).
You people know TS's parser better than I - so you're more aware of whether or not it's feasible to compute the loc up front without a binary search or not. If it's not - then we can just close this out as non-actionable.
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.
Hướng nghiên cứu
Bắt đầu bằng cách đọc trình phân tích cú pháp TypeScript và phép tính node-location hiện có được mô tả trong issue, sau đó so sánh cách @typescript-eslint sử dụng các vị trí AST của ESLint. Issue không nêu tên tệp hoặc bài kiểm thử nào; để được xem là hoàn tất, cần có một tùy chọn được chấp nhận cho việc tính loc eager và bằng chứng cho thấy tùy chọn đó tránh được chi phí tìm kiếm nhị phân đã được báo cáo mà không thay đổi hành vi hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- eslint, typescript
- Lĩnh vực
- compilers, performance
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100