Coverage could point out writes that make method calls slower

Đang mở
#1,149 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #1153 của @alantriesagain — đã đóng, không merge

Đá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
25/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript

Hướng nghiên cứu

Read the open pull request #1153 and the related issues #1148 and #963 first; the issue names no source files or tests. The request is for scriptc coverage to report writes that make method calls slower and support --fail-on=slow-paths, but it leaves diagnostic and CLI design choices open. Done would mean the report identifies affected methods, gives a hint, and CI can fail on those sites.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

scriptc coverage tells us whether a program compiles and where it may behave differently from Node. It does not say when a single line makes a large part of the program slower. In our case (#1148) one write made every method call go through a lookup on the object, and coverage still reported "fully static". The follow-up in #963 mentions the same blind spot: "static coverage was 100% on every broken build".

Take this program:

class Counter {
  n = 0;
  bump(): void {
    this.n++;
  }
}

function remember(cache: Record<string, unknown>, key: string, value: unknown): void {
  cache[key] = value;
}

const counter = new Counter();
remember({}, "last", counter);
for (let i = 0; i < 1000; i++) counter.bump();
console.log(counter.n);

cache[key] = value could replace any method, so every call to bump is looked up on the object. That is correct, but nothing in the coverage report shows it. It would help to see these lines listed, with the methods they affect and a hint on how to avoid it, and to have a way to fail CI on them for projects that care about speed. We use something like this:

scriptc coverage report-demo.ts

  statements analyzed   8
  compile statically    8  (100%)

  fully static — all analyzed statements compile to native code.

  slower natively   1 site (compiles and behaves like Node; makes calls slower)
      ×1  SC7001  this write's key can name any property, so calls to method 'bump' dispatch dynamically: each call reads the method from the instance and boxes the receiver
          at report-demo.ts:9:3
          hint: type the key as a number or a string literal, write into an object created in this scope, or keep the entries in a Map

with scriptc coverage --fail-on=slow-paths in CI.

We built this for our own use and opened #1153 in case it is useful. It adds a new SC7xxx band of notes and a --fail-on value, which are design choices for you to make, so please treat the PR as a starting point, or close it, as you see fit.

Ngôn ngữ chính
TypeScript
Star
6.7k
Fork
229
Merge trung bình
14 giờ 29 phút
Pull request đã merge (30 ngày)
787

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.