Coverage could point out writes that make method calls slower

Abierto
#1,149 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #1153 de @alantriesagain — cerrado sin fusionar

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
6.7k
Forks
229
Merge medio
14 h 29 min
PR fusionados (30 d)
787

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de vercel-labs/scriptc

Todos los issues de vercel-labs/scriptc

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.