Skip to content

Conversation

@na9da
Copy link
Collaborator

@na9da na9da commented Apr 29, 2024

What this PR does

Save 16 seconds from typescript compile step.

Running typescript analyzer reports a hotspot when compiling Terria code (see report below). Apparently the OneKeyFrom type used for typing the Text and Box component props is pretty expensive to type check.

I am not sure if there is a better fix, but for now I have removed OneKeyFrom which loosens the type checking a bit, but I think this is a good compromise as it:

  • saves more than 16 seconds off current compilation time
  • avoids future use of Text component from further increasing the compile time

Typescript analyzer report:

$ npx @typescript/analyze-trace tstrace

Hot Spots
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/Styled/Checkbox/Checkbox.tsx (6801ms)
│  └─ Check deferred node from (line 78, char 7) to (line 121, char 18) (6791ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/ReactViews/StandardUserInterface/TrainerBar/TrainerBar.tsx (1180ms)
│  └─ Check deferred node from (line 87, char 9) to (line 89, char 19) (790ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/Styled/Text.tsx (992ms)
│  └─ Check variable declaration from (line 227, char 4) to (line 233, char 1) (652ms)
│     └─ Check expression from (line 227, char 15) to (line 233, char 1) (652ms)
│        └─ Check expression from (line 227, char 15) to (line 233, char 1) (652ms)
│           └─ Check expression from (line 227, char 15) to (line 227, char 34) (650ms)
│              └─ Check expression from (line 227, char 15) to (line 227, char 28) (650ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/ReactViews/Workbench/Controls/OpacitySection.tsx (841ms)
│  └─ Check deferred node from (line 52, char 11) to (line 56, char 25) (835ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/ReactViews/Feedback/FeedbackForm.tsx (699ms)
│  └─ Check deferred node from (line 187, char 11) to (line 198, char 18) (547ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/ReactViews/SelectableDimensions/SelectableDimension.tsx (620ms)
│  └─ Check deferred node from (line 39, char 13) to (line 44, char 20) (609ms)
├─ Check file /home/san244/work/terriamap-editor/packages/terriajs/lib/ReactViews/Map/BottomBar/DistanceLegend.tsx (551ms)
│  └─ Check deferred node from (line 191, char 9) to (line 199, char 16) (542ms)
└─ Check file /home/san244/work/terriamap-editor/node_modules/@types/styled-components/index.d.ts (525ms)

Duplicate packages
└─ @types/d3-color
   ├─ Version 3.0.2 from /home/san244/work/terriamap-editor/node_modules/@types/d3-color
   └─ Version 1.4.2 from /home/san244/work/terriamap-editor/node_modules/@types/d3-interpolate/node_modules/@types/d3-color

Test me

Before:

time tsc

real    0m29.036s
user    0m43.665s
sys     0m1.237s

After:

time tsc

real    0m12.047s
user    0m24.441s
sys     0m0.581s

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist) Only changes the types
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

na9da added 2 commits April 29, 2024 15:00
Save 16 seconds from typescript compile step.
Copy link
Contributor

@tephenavies tephenavies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. This is a good tradeoff

@na9da na9da merged commit f073bd1 into main Apr 29, 2024
@na9da na9da deleted the simplify-text-type branch April 29, 2024 06:00
@pjonsson
Copy link
Contributor

If duplicate packages are an issue for type analyzer performance, I believe #7105 eliminates version 1.4.2 of d3-color listed at the bottom of the analyzer report in this PR.

@na9da
Copy link
Collaborator Author

na9da commented Apr 30, 2024

@pjonsson - that's really nice.

According to the docs, having duplicate typings is certainly not ideal.
Thanks for your PR, I'll have a look at it 👍

@pjonsson
Copy link
Contributor

pjonsson commented May 1, 2024

@na9da oh, that link provided a really clear explanation. My PR was for security issues, so I'm glad it killed two birds with one stone.

If the type analyzer wants as few duplicate packages as possible, I'm guessing you roughly want to have the latest version of all packages (so the only duplicates are from packages that have not been updated for a long time). If you manage to bring most dependencies in package.json up to date, Dependabot can then be configured to automatically provide pull requests when there are new versions of packages released.

(Dependabot can automatically send pull requests for other eco-systems too, TerriaJS/TerriaMap#665 is for having Dependabot keep the Github actions up to date.)

@na9da
Copy link
Collaborator Author

na9da commented May 2, 2024

@pjonsson We did have dependabot until sometime ago but decided to turn it off until we deal with the current backlog. We will turn it back on once we have it under control, so thanks for all the PRs.

@pjonsson
Copy link
Contributor

pjonsson commented May 2, 2024

@na9da I have never used it myself, but I know Dependabot can be configured to only make pull requests for security updates.

If Dependabot was turned off a long time ago, it might be worth evaluating if that strategy has served your goals well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants