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

Long running encodedSemanticClassifications-full request #59655

Open
roryscot opened this issue Aug 16, 2024 · 9 comments
Open

Long running encodedSemanticClassifications-full request #59655

roryscot opened this issue Aug 16, 2024 · 9 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@roryscot
Copy link

roryscot commented Aug 16, 2024

πŸ”Ž Search Terms

@RyanCavanaugh requested that I create a new issue

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 5.5.4

⏯ Playground Link

No response

πŸ’» Code

  • Clone example repo
  • run npm i
  • navigate to line 26 in VSCode
  • try to use auto-suggestion menu (Command + .)

The warning React Hook useEffect has a missing dependency: 'getProfile'. Either include it or remove the dependency array.eslint[react-hooks/exhaustive-deps](https://github.com/facebook/react/issues/14920) should appear on line 26

πŸ™ Actual behavior

2024-08-15 18:57:48.766 [trace] <semantic> Response received: encodedSemanticClassifications-full (210). Request took 155445 ms. Success: true { "spans": [ 467, 11, 2817, 493, 5, 2560, 500, 4, 2089, 509, 10, 2816, 520, 11, 2056, 543, 7, 2089, 552, 10, 2857, 566, 8, 2816, 575, 12, 1536, 600, 6, 2089, 609, 10, 2816, 620, 21, 2056, 686, 10, 2857, 699, 11, 2816, 737, 4, 2560, 743, 8, 2089, 762, 6, 2088, 769, 6, 2560, 776, 11, 2560, 788, 4, 3072, 801, 6, 2561, 819, 5, 2561, 838, 2, 2561, 842, 4, 2088, 848, 10, 2560, 899, 8, 2088, 908, 6, 2576, 918, 10, 2856, 929, 8, 2088, 949, 6, 2088, 956, 6, 2560, 963, 11, 2560, 976, 4, 2088, 987, 9, 2816, 1009, 10, 2856, 1029, 6, 2088, 1036, 6, 2560, 1043, 11, 2560, 1056, 4, 2088, 1124, 7, 2088, 1160, 4, 2561, 1178, 7, 2561, 1205, 8, 2561, 1240, 5, 2561, 1259, 7, 2561, 1286, 8, 2561, 1321, 12, 2561, 1347, 7, 2561, 1374, 8, 2561, 1409, 6, 2561, 1429, 7, 2561, 1456, 8, 2561 ], "endOfLineState": 0 }

encodedSemanticClassifications-full took almost a minute and an half.

πŸ™‚ Expected behavior

encodedSemanticClassifications-full should take less than a few seconds.

Additional information about the issue

When I remove the import for Schema, everything seems to work as expected. The Schema is a somewhat complex generated type whose definition is here.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 16, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Aug 16, 2024
@jakebailey
Copy link
Member

This seems to be very similar to #56081 (sorta) / #52345 / #55948, something I tried to help fix a while back. This repo seems to spend basically all of its time in removeStringLiteralsMatchedByTemplateLiterals, which means there's some truly massive union of literals being processed.

image

vscode-profile-2024-08-19-13-31-03.cpuprofile

@jakebailey
Copy link
Member

jakebailey commented Aug 19, 2024

That being said, I'm confused as to this repro; it mentions an eslint error showing up (not TS related?), and the above perf problem was coming from diagnostics themselves, not semantic highlighting. Just running tsc in the repro takes a very long time. Is the problem the perf in general?

@roryscot
Copy link
Author

roryscot commented Aug 19, 2024

The eslint error is only reflective of a performance issue, yes. Though the perf issue seems to originate in TS--specifically in the Schema. I thought it might be a recursion issue.

@jakebailey
Copy link
Member

I'm not sure where this is happening, but something in this example is attempting to create a union with 628,109 types, 1,733 of which are template literals, and 626,376 are string literals that have to be matched against those template literals. That means needing to do 1,085,509,608 string-to-string-literal inferences.

@jakebailey
Copy link
Member

Adding in a limiter to bail out when this situation happens points here:

src/components/UserProfile/UserProfile.tsx:14:38 - error TS2590: Expression produces a union type that is too complex to represent.

 14     const { data: profiles } = await client.models.UserProfile.list({
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 15       filter: {
    ~~~~~~~~~~~~~~~
... 
 19       },
    ~~~~~~~~
 20     });
    ~~~~~~

@jakebailey
Copy link
Member

Just to show what those strings are, if that helps you narrow down the bad code:

healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.predictiveAnalytics.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.articles.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.medicationLogs.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.symptomLogs.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.contraceptiveMethods.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.contraceptiveReminders.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.ovulationTests.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.basalBodyTemperatures.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.menstrualHealthInsights.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.ovulationPredictions.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.ovulationCycles.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.birthday.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.avatar.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.profileOwner.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.fertilityWindows.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.progressReports.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.uuid.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.OvulationCycleAnalysis.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.id.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.userProfile.email.*
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.updatedAt
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.createdAt
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.settingValue
healthGoals.userProfile.automatedUpdates.userProfile.privacySettings.settingName

@jakebailey
Copy link
Member

Can you try the build on #59759 (comment) to see if that fixes things in general?

@roryscot
Copy link
Author

It does not seem to make a difference

@jakebailey
Copy link
Member

Hm, okay. I rechecked the profile for just a completion call, and most of the time is now spent in auto-imports.

vscode-profile-2024-08-26-11-20-10.cpuprofile

In my logs, I do not see the call from the issue title taking time:

Perf 2101 [11:30:31.389] 7::encodedSemanticClassifications-full: elapsed time (in milliseconds) 4.7975

But do see completion being slow:

Perf 2123 [11:30:38.555] 11::completionInfo: elapsed time (in milliseconds) 7163.8768

Can you turn on logging and send tsserver logs?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants