Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer type predicates for functions with multiple returns #58154

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

danvk
Copy link
Contributor

@danvk danvk commented Apr 11, 2024

Follow-on to #57465

The original PR restricted itself to functions with a single return. This PR lifts that restriction.

This allows us to infer predicates for constructs like this:

// infers x is string | Date
function ifElseIfPredicate(x: string | number | Date) {
  if (typeof x === 'string') {
    return true;
  } else if (x instanceof Date) {
    return true;
  }
  return false;
}

or

// infers str is "a" | "b" | "c"
function switchPredicate(str: string) {
  switch (str) {
    case 'a':
    case 'b':
    case 'c':
      return true
    default:
      return false
  }
}

How this works

Type predicate inference works by rewriting return statements from:

function foo(p: InitType) {
  return expr_involving_p;
}

to:

function foo(p: InitType) {
  if (expr_involving_p) {
    p  // TrueType
  } else {
    p  // FalseType
  }
}

If TrueType != InitType then we have a candidate for a type predicate. To generalize this to multiple returns, we determine the TrueType at each return statement and union them. These are all the parameter types for which the function can return true.

To verify the "if and only if" semantics of type predicates, we feed the type predicate type back into the function and look at all the false cases. For a valid type predicate, these should all be never.

I've also special-cased return true and return false. These weren't especially relevant when getTypePredicateFromBody only allowed one return, but they're very relevant now.

Why this might be a good idea

Like #57465, this should only produce valid type predicates, which should result in more precise types.

This makes inferred type predicates less sensitive to seemingly irrelevant refactors, such as:

// may have an inferred type predicate
function f1(arg) {
  return cond1(arg) && cond2(arg);
}
// cannot have an inferred type predicate in TS 5.5
function f1(arg) {
  if (!cond1(arg)) return false;
  return cond2(arg);
}

These kinds of refactors don't affect inferred return types, so it may be surprising that they affect inferred type predicates.

While this does result in predicate inference running on more functions, the perf impact seems to be minimal.

Why this might not be a good idea

Multi-return type predicates are not as common as single-return type predicates:

So the impact will be relatively small compared to the original change.

This does make the type predicate inference code a bit harder to follow since we're always working with Type[] instead of Type.

Moreover, I got a new circularity error in emitter.ts. This would also have been a new circularity error with #57465, but the type predicate inference code didn't run because one of the functions had two returns. This change increases the odds that this happens on existing code. This error no longer happens.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 11, 2024
@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests comparing main and refs/pull/58154/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,945k (± 0.01%) 295,933k (± 0.01%) ~ 295,885k 295,972k p=0.630 n=6
Parse Time 2.65s (± 0.51%) 2.66s (± 0.51%) ~ 2.63s 2.67s p=0.547 n=6
Bind Time 0.82s (± 1.62%) 0.82s (± 1.33%) ~ 0.81s 0.83s p=0.859 n=6
Check Time 8.23s (± 0.27%) 8.25s (± 0.25%) ~ 8.21s 8.27s p=0.517 n=6
Emit Time 7.05s (± 0.15%) 7.05s (± 0.22%) ~ 7.03s 7.07s p=0.218 n=6
Total Time 18.77s (± 0.08%) 18.77s (± 0.20%) ~ 18.73s 18.83s p=0.511 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 191,643k (± 0.02%) 194,175k (± 0.92%) +2,532k (+ 1.32%) 191,823k 195,435k p=0.005 n=6
Parse Time 1.35s (± 0.62%) 1.37s (± 1.00%) ~ 1.35s 1.39s p=0.109 n=6
Bind Time 0.72s (± 0.57%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=0.405 n=6
Check Time 9.43s (± 0.25%) 9.45s (± 0.71%) ~ 9.38s 9.54s p=0.748 n=6
Emit Time 2.61s (± 1.16%) 2.62s (± 1.20%) ~ 2.56s 2.64s p=0.685 n=6
Total Time 14.11s (± 0.29%) 14.15s (± 0.54%) ~ 14.09s 14.26s p=0.520 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,723k (± 0.01%) 347,734k (± 0.00%) ~ 347,723k 347,749k p=0.630 n=6
Parse Time 2.48s (± 0.59%) 2.48s (± 0.54%) ~ 2.46s 2.50s p=1.000 n=6
Bind Time 0.89s (± 0.58%) 0.89s (± 0.91%) ~ 0.89s 0.91s p=0.114 n=6
Check Time 6.97s (± 0.51%) 6.96s (± 0.17%) ~ 6.95s 6.98s p=0.871 n=6
Emit Time 4.07s (± 0.36%) 4.07s (± 0.25%) ~ 4.06s 4.08s p=0.530 n=6
Total Time 14.41s (± 0.16%) 14.42s (± 0.19%) ~ 14.38s 14.46s p=0.808 n=6
TFS - node (v18.15.0, x64)
Memory used 302,608k (± 0.01%) 302,608k (± 0.01%) ~ 302,585k 302,652k p=0.810 n=6
Parse Time 2.39s (± 0.97%) 2.41s (± 0.59%) ~ 2.39s 2.43s p=0.075 n=6
Bind Time 1.16s (± 0.35%) 1.16s (± 0.35%) ~ 1.16s 1.17s p=0.218 n=6
Check Time 7.45s (± 0.31%) 7.46s (± 0.49%) ~ 7.40s 7.50s p=0.331 n=6
Emit Time 4.27s (± 0.58%) 4.27s (± 0.75%) ~ 4.23s 4.32s p=0.684 n=6
Total Time 15.27s (± 0.26%) 15.31s (± 0.36%) ~ 15.24s 15.36s p=0.260 n=6
material-ui - node (v18.15.0, x64)
Memory used 510,584k (± 0.01%) 510,609k (± 0.01%) ~ 510,579k 510,651k p=0.128 n=6
Parse Time 2.66s (± 0.51%) 2.67s (± 0.76%) ~ 2.64s 2.70s p=0.164 n=6
Bind Time 0.98s (± 1.58%) 0.99s (± 0.83%) ~ 0.98s 1.00s p=0.510 n=6
Check Time 17.20s (± 0.28%) 17.21s (± 0.31%) ~ 17.11s 17.25s p=0.288 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.84s (± 0.21%) 20.88s (± 0.29%) ~ 20.77s 20.93s p=0.226 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,742,692k (± 0.00%) 1,742,670k (± 0.00%) ~ 1,742,605k 1,742,747k p=0.261 n=6
Parse Time 7.85s (± 0.51%) 7.85s (± 0.78%) ~ 7.79s 7.96s p=0.808 n=6
Bind Time 2.74s (± 0.89%) 2.75s (± 0.87%) ~ 2.71s 2.78s p=0.566 n=6
Check Time 66.40s (± 0.38%) 66.40s (± 0.47%) ~ 65.87s 66.75s p=0.872 n=6
Emit Time 0.16s (± 0.00%) 0.16s (± 3.29%) ~ 0.15s 0.16s p=0.174 n=6
Total Time 77.15s (± 0.34%) 77.16s (± 0.38%) ~ 76.62s 77.49s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,303,056k (± 0.04%) 2,302,781k (± 0.02%) ~ 2,302,126k 2,303,189k p=1.000 n=6
Parse Time 7.38s (± 0.63%) 7.37s (± 1.18%) ~ 7.29s 7.53s p=0.575 n=6
Bind Time 2.76s (± 0.58%) 2.73s (± 0.88%) ~ 2.71s 2.77s p=0.065 n=6
Check Time 48.73s (± 0.41%) 48.91s (± 0.72%) ~ 48.44s 49.48s p=0.471 n=6
Emit Time 3.88s (± 2.57%) 3.86s (± 3.57%) ~ 3.72s 4.12s p=0.689 n=6
Total Time 62.75s (± 0.38%) 62.90s (± 0.66%) ~ 62.41s 63.62s p=0.520 n=6
self-build-src-public-api - node (v18.15.0, x64)
Memory used 2,377,109k (± 0.03%) 2,377,257k (± 0.03%) ~ 2,376,567k 2,378,563k p=0.936 n=6
Parse Time 7.65s (± 1.03%) 7.65s (± 0.81%) ~ 7.54s 7.72s p=0.810 n=6
Bind Time 2.50s (± 0.89%) 2.48s (± 0.49%) ~ 2.47s 2.50s p=0.171 n=6
Check Time 49.30s (± 0.14%) 49.23s (± 0.37%) ~ 49.01s 49.46s p=0.810 n=6
Emit Time 3.91s (± 3.34%) 3.94s (± 1.93%) ~ 3.86s 4.07s p=0.873 n=6
Total Time 63.35s (± 0.22%) 63.33s (± 0.34%) ~ 63.12s 63.68s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Memory used 418,399k (± 0.01%) 418,502k (± 0.01%) +102k (+ 0.02%) 418,447k 418,549k p=0.005 n=6
Parse Time 4.18s (± 0.41%) 4.18s (± 0.33%) ~ 4.16s 4.20s p=0.742 n=6
Bind Time 1.59s (± 2.71%) 1.58s (± 0.57%) ~ 1.57s 1.59s p=1.000 n=6
Check Time 22.05s (± 0.25%) 22.08s (± 0.35%) ~ 21.97s 22.20s p=0.470 n=6
Emit Time 1.69s (± 1.10%) 1.70s (± 1.25%) ~ 1.66s 1.72s p=0.278 n=6
Total Time 29.51s (± 0.29%) 29.54s (± 0.30%) ~ 29.44s 29.71s p=0.470 n=6
vscode - node (v18.15.0, x64)
Memory used 2,907,545k (± 0.00%) 2,907,535k (± 0.00%) ~ 2,907,468k 2,907,596k p=0.689 n=6
Parse Time 15.93s (± 0.26%) 15.99s (± 0.47%) ~ 15.92s 16.13s p=0.077 n=6
Bind Time 4.91s (± 0.47%) 4.91s (± 0.38%) ~ 4.88s 4.93s p=0.628 n=6
Check Time 86.42s (± 0.27%) 85.99s (± 0.26%) -0.43s (- 0.50%) 85.71s 86.39s p=0.020 n=6
Emit Time 23.62s (± 0.49%) 23.55s (± 0.62%) ~ 23.31s 23.72s p=0.748 n=6
Total Time 130.88s (± 0.20%) 130.44s (± 0.25%) -0.44s (- 0.34%) 129.89s 130.84s p=0.031 n=6
webpack - node (v18.15.0, x64)
Memory used 408,686k (± 0.01%) 408,690k (± 0.01%) ~ 408,646k 408,774k p=0.748 n=6
Parse Time 3.87s (± 0.72%) 3.86s (± 0.48%) ~ 3.85s 3.90s p=0.870 n=6
Bind Time 1.67s (± 1.05%) 1.66s (± 0.93%) ~ 1.63s 1.67s p=0.618 n=6
Check Time 16.73s (± 0.30%) 16.71s (± 0.29%) ~ 16.64s 16.78s p=0.298 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.27s (± 0.37%) 22.23s (± 0.27%) ~ 22.17s 22.31s p=0.521 n=6
xstate - node (v18.15.0, x64)
Memory used 670,847k (± 0.02%) 670,841k (± 0.01%) ~ 670,735k 670,942k p=1.000 n=6
Parse Time 4.98s (± 0.35%) 4.98s (± 0.68%) ~ 4.95s 5.03s p=0.520 n=6
Bind Time 2.32s (± 0.76%) 2.32s (± 0.85%) ~ 2.30s 2.35s p=0.870 n=6
Check Time 4.20s (± 0.79%) 4.24s (± 1.48%) ~ 4.15s 4.31s p=0.295 n=6
Emit Time 0.03s (± 0.00%) 0.03s (± 0.00%) ~ 0.03s 0.03s p=1.000 n=6
Total Time 11.54s (± 0.48%) 11.58s (± 0.79%) ~ 11.45s 11.71s p=0.419 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos comparing main and refs/pull/58154/merge:

Everything looks good!

@danvk
Copy link
Contributor Author

danvk commented Apr 12, 2024

👀 So minimal perf impact and no breaks beyond the self-check circularity issue. Maybe this is a good idea? 🤔

@jakebailey
Copy link
Member

@typescript-bot test top800

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 12, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top800 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 800 repos comparing main and refs/pull/58154/merge:

Everything looks good!

@danvk
Copy link
Contributor Author

danvk commented Apr 12, 2024

I put up #58173, which reports an error whenever it infers a type predicate for a function with multiple return statements. That should clarify how common this pattern is in the wild.

@danvk
Copy link
Contributor Author

danvk commented Apr 12, 2024

Results of the experiment:

  • three new type predicates in TypeScript itself, one of which had an impact
  • one new type predicate in pyright
  • three new type predicates in the top400 suite

So not many functions match this pattern in the wild, but a few do and there's also not a big perf impact. Up to TS team whether this is a helpful generalization. See @jakebailey's comment #58173 (comment)

@anka-213
Copy link

I would love to have this, since it allows splitting up type predicates instead of having to write them as a single long expression. I'm surprised that things like

function isArrayOfStrings(x: unknown): x is string[] {
  if (!x instanceof Array) return false;
  
  return x.every((y) => typeof y === 'string');
}

didn't occur more in your experiment, since I've seen it pretty often for more complicated type predicates.

@danvk
Copy link
Contributor Author

danvk commented Apr 29, 2024

@anka-213 if there are examples in the wild that you can point to, that would be helpful. This makes me realize that my experiment (#58173) would not tell us about existing type predicates with 2+ returns, since the predicate inference code doesn't run if there's an explicit return type annotation. In other words, it would not have detected your isArrayOfStrings function. Finding functions like this would be another interesting data point.

FWIW you can break up the long expression by factoring out a variable, you just can't break up the control flow:

// function isArrayOfStrings(x: unknown): x is string[]
function isArrayOfStrings(x: unknown) {
  const isArray = Array.isArray(x);
  return isArray && (x.every((y) => typeof y === 'string'));
}

playground

@danvk danvk changed the title Experiment: Infer type predicates for functions with multiple returns Infer type predicates for functions with multiple returns May 15, 2024
@danvk danvk marked this pull request as ready for review July 11, 2024 19:23
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@danvk
Copy link
Contributor Author

danvk commented Jul 11, 2024

I've merged upstream changes and brought the implementation more in line with main to reduce the diff. I've also updated the PR description in light of the experiments and performance numbers from April. @jakebailey it would be interesting to get new performance numbers to see if the "minimal impact" holds up.

I can open an issue like typescript-bot suggests if that would be a more appropriate way to discuss the merits of this extension.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 11, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/58154/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,153 62,209 +56 (+ 0.09%) ~ ~ p=0.001 n=6
Types 50,242 50,258 +16 (+ 0.03%) ~ ~ p=0.001 n=6
Memory used 193,995k (± 0.97%) 192,611k (± 0.82%) ~ 191,875k 195,832k p=0.066 n=6
Parse Time 1.30s (± 0.63%) 1.30s (± 0.31%) ~ 1.30s 1.31s p=0.584 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.48s (± 0.76%) 9.48s (± 0.42%) ~ 9.43s 9.55s p=1.000 n=6
Emit Time 2.76s (± 0.48%) 2.97s (± 0.97%) 🔻+0.21s (+ 7.67%) 2.93s 3.00s p=0.005 n=6
Total Time 14.26s (± 0.51%) 14.46s (± 0.40%) +0.21s (+ 1.46%) 14.39s 14.56s p=0.005 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 944,114 944,114 ~ ~ ~ p=1.000 n=6
Types 407,050 407,050 ~ ~ ~ p=1.000 n=6
Memory used 1,218,405k (± 0.00%) 1,218,378k (± 0.01%) ~ 1,218,270k 1,218,499k p=0.378 n=6
Parse Time 6.69s (± 0.57%) 6.73s (± 0.77%) ~ 6.66s 6.82s p=0.418 n=6
Bind Time 1.88s (± 0.67%) 1.88s (± 0.43%) ~ 1.87s 1.89s p=0.558 n=6
Check Time 30.61s (± 0.24%) 30.71s (± 0.49%) ~ 30.53s 30.89s p=0.295 n=6
Emit Time 13.59s (± 0.91%) 13.60s (± 0.42%) ~ 13.55s 13.68s p=0.686 n=6
Total Time 52.78s (± 0.36%) 52.91s (± 0.40%) ~ 52.69s 53.28s p=0.378 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,130,296 2,130,291 -5 (- 0.00%) ~ ~ p=0.001 n=6
Types 927,656 927,643 -13 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 2,107,060k (± 0.01%) 2,107,028k (± 0.00%) ~ 2,106,977k 2,107,102k p=0.810 n=6
Parse Time 6.62s (± 0.30%) 6.61s (± 0.23%) ~ 6.59s 6.63s p=1.000 n=6
Bind Time 2.33s (± 0.70%) 2.32s (± 0.47%) ~ 2.30s 2.33s p=0.622 n=6
Check Time 70.41s (± 0.75%) 70.72s (± 0.40%) ~ 70.35s 71.07s p=0.336 n=6
Emit Time 0.14s (± 2.95%) 0.14s (± 4.51%) ~ 0.13s 0.15s p=0.673 n=6
Total Time 79.49s (± 0.64%) 79.79s (± 0.35%) ~ 79.40s 80.12s p=0.378 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,226,005 1,226,072 +67 (+ 0.01%) ~ ~ p=0.001 n=6
Types 261,615 261,670 +55 (+ 0.02%) ~ ~ p=0.001 n=6
Memory used 2,339,381k (± 0.03%) 2,339,575k (± 0.02%) ~ 2,339,026k 2,340,123k p=0.378 n=6
Parse Time 6.06s (± 0.71%) 6.07s (± 1.29%) ~ 6.00s 6.20s p=0.810 n=6
Bind Time 2.24s (± 0.56%) 2.24s (± 0.56%) ~ 2.23s 2.26s p=0.934 n=6
Check Time 40.34s (± 0.27%) 40.19s (± 0.38%) ~ 40.01s 40.40s p=0.128 n=6
Emit Time 3.86s (± 2.14%) 3.85s (± 0.91%) ~ 3.78s 3.87s p=0.936 n=6
Total Time 52.51s (± 0.27%) 52.37s (± 0.30%) ~ 52.13s 52.56s p=0.230 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,226,005 1,226,072 +67 (+ 0.01%) ~ ~ p=0.001 n=6
Types 261,615 261,670 +55 (+ 0.02%) ~ ~ p=0.001 n=6
Memory used 2,413,110k (± 0.02%) 2,413,066k (± 0.02%) ~ 2,412,040k 2,413,566k p=0.471 n=6
Parse Time 5.25s (± 0.55%) 5.24s (± 0.79%) ~ 5.19s 5.31s p=0.575 n=6
Bind Time 1.68s (± 0.50%) 1.69s (± 0.95%) ~ 1.67s 1.71s p=0.667 n=6
Check Time 34.64s (± 0.21%) 34.61s (± 0.12%) ~ 34.55s 34.65s p=0.335 n=6
Emit Time 3.28s (± 1.59%) 3.29s (± 1.16%) ~ 3.24s 3.33s p=0.630 n=6
Total Time 44.87s (± 0.33%) 44.82s (± 0.14%) ~ 44.74s 44.91s p=0.630 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 258,315 258,380 +65 (+ 0.03%) ~ ~ p=0.001 n=6
Types 104,817 104,863 +46 (+ 0.04%) ~ ~ p=0.001 n=6
Memory used 427,248k (± 0.03%) 427,452k (± 0.03%) +204k (+ 0.05%) 427,294k 427,650k p=0.045 n=6
Parse Time 3.31s (± 0.55%) 3.31s (± 0.52%) ~ 3.29s 3.33s p=0.931 n=6
Bind Time 1.31s (± 1.01%) 1.32s (± 0.93%) ~ 1.29s 1.32s p=0.673 n=6
Check Time 17.81s (± 0.21%) 17.84s (± 0.28%) ~ 17.77s 17.90s p=0.294 n=6
Emit Time 1.65s (± 0.54%) 1.63s (± 0.55%) -0.02s (- 1.21%) 1.62s 1.64s p=0.011 n=6
Total Time 24.09s (± 0.16%) 24.10s (± 0.29%) ~ 24.00s 24.17s p=0.688 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,565 224,568 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Types 93,734 93,738 +4 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 369,536k (± 0.02%) 369,537k (± 0.02%) ~ 369,425k 369,685k p=1.000 n=6
Parse Time 3.42s (± 1.05%) 3.46s (± 1.08%) ~ 3.40s 3.50s p=0.198 n=6
Bind Time 1.94s (± 0.73%) 1.95s (± 0.79%) ~ 1.93s 1.96s p=0.276 n=6
Check Time 19.17s (± 0.38%) 19.19s (± 0.29%) ~ 19.15s 19.30s p=0.630 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.53s (± 0.34%) 24.59s (± 0.33%) ~ 24.49s 24.72s p=0.335 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,889,872 2,889,874 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 977,787 977,791 +4 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,053,447k (± 0.00%) 3,053,475k (± 0.00%) ~ 3,053,403k 3,053,544k p=0.689 n=6
Parse Time 16.90s (± 0.51%) 16.83s (± 0.38%) ~ 16.77s 16.94s p=0.146 n=6
Bind Time 5.12s (± 0.40%) 5.11s (± 0.42%) ~ 5.08s 5.14s p=0.252 n=6
Check Time 91.37s (± 2.95%) 92.13s (± 2.26%) ~ 89.55s 94.56s p=0.575 n=6
Emit Time 27.68s (± 9.12%) 27.10s (± 7.87%) ~ 24.40s 29.46s p=0.689 n=6
Total Time 141.07s (± 0.25%) 141.16s (± 0.37%) ~ 140.52s 142.03s p=0.936 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 267,239 267,239 ~ ~ ~ p=1.000 n=6
Types 108,815 108,815 ~ ~ ~ p=1.000 n=6
Memory used 411,833k (± 0.02%) 411,847k (± 0.02%) ~ 411,730k 411,957k p=0.936 n=6
Parse Time 4.73s (± 0.19%) 4.76s (± 0.48%) +0.03s (+ 0.63%) 4.74s 4.80s p=0.011 n=6
Bind Time 2.08s (± 1.11%) 2.09s (± 0.84%) ~ 2.07s 2.11s p=0.408 n=6
Check Time 20.71s (± 0.41%) 20.74s (± 0.30%) ~ 20.68s 20.82s p=0.470 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 27.52s (± 0.34%) 27.60s (± 0.29%) ~ 27.50s 27.71s p=0.228 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 510,475 510,475 ~ ~ ~ p=1.000 n=6
Types 161,600 161,600 ~ ~ ~ p=1.000 n=6
Memory used 448,046k (± 0.06%) 448,001k (± 0.08%) ~ 447,591k 448,395k p=1.000 n=6
Parse Time 3.14s (± 1.06%) 3.12s (± 0.48%) ~ 3.11s 3.15s p=0.466 n=6
Bind Time 1.17s (± 0.64%) 1.17s (± 0.35%) ~ 1.17s 1.18s p=1.000 n=6
Check Time 16.95s (± 0.58%) 16.99s (± 0.55%) ~ 16.86s 17.13s p=0.520 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 21.26s (± 0.50%) 21.28s (± 0.46%) ~ 21.15s 21.44s p=0.688 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@danvk
Copy link
Contributor Author

danvk commented Jul 11, 2024

Other than the compiler-unions emit time, this looks like ~0 impact. I can take a look at whether there's some giant type predicate being emitted that would account for that, but I'm skeptical since we didn't see change in this number back in April and the behavior of the PR shouldn't be different.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/58154/merge:

Everything looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants