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

[labs/analyzer] Add template utils to analyzer and use them in the compiler #4261

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

justinfagnani
Copy link
Collaborator

Builds on #4260 (for use in tests)

This moves the isLitTaggedTemplateExpression template utility from the compiler to the analyzer. The analyzer will need these same utilities to detect lit-html template expressions for template analysis.

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2023

🦋 Changeset detected

Latest commit: 6bf89aa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@lit-labs/analyzer Minor
@lit-labs/cli Patch
@lit-labs/compiler Patch
@lit-labs/gen-manifest Patch
@lit-labs/gen-utils Patch
@lit-labs/gen-wrapper-angular Patch
@lit-labs/gen-wrapper-react Patch
@lit-labs/gen-wrapper-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +8% (-0.19ms - +0.84ms)
    this-change vs tip-of-tree

render

  • this-change: 47.16ms - 49.63ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +3% (-0.72ms - +0.63ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +1% (-1.19ms - +0.38ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +2% (-0.82ms - +0.52ms)
    this-change vs tip-of-tree

update

  • this-change: 539.79ms - 551.22ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -7% - +6% (-2.82ms - +2.32ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -6% - +1% (-4.20ms - +0.56ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-12.47ms - +9.33ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 537.59ms - 548.88ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-11.97ms - +9.34ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
47.16ms - 49.63ms-

update

VersionAvg timevs
539.79ms - 551.22ms-

update-reflect

VersionAvg timevs
537.59ms - 548.88ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
18.19ms - 19.09ms-unsure 🔍
-4% - +3%
-0.72ms - +0.63ms
unsure 🔍
-3% - +4%
-0.53ms - +0.79ms
tip-of-tree
tip-of-tree
18.18ms - 19.19msunsure 🔍
-3% - +4%
-0.63ms - +0.72ms
-unsure 🔍
-3% - +5%
-0.53ms - +0.88ms
previous-release
previous-release
18.02ms - 19.00msunsure 🔍
-4% - +3%
-0.79ms - +0.53ms
unsure 🔍
-5% - +3%
-0.88ms - +0.53ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
38.28ms - 42.01ms-unsure 🔍
-7% - +6%
-2.82ms - +2.32ms
unsure 🔍
-11% - +1%
-4.59ms - +0.53ms
tip-of-tree
tip-of-tree
38.63ms - 42.16msunsure 🔍
-6% - +7%
-2.32ms - +2.82ms
-unsure 🔍
-10% - +2%
-4.27ms - +0.71ms
previous-release
previous-release
40.42ms - 43.93msunsure 🔍
-1% - +12%
-0.53ms - +4.59ms
unsure 🔍
-2% - +11%
-0.71ms - +4.27ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
10.76ms - 11.47ms-unsure 🔍
-2% - +8%
-0.19ms - +0.84ms
unsure 🔍
-7% - +1%
-0.77ms - +0.17ms
tip-of-tree
tip-of-tree
10.42ms - 11.16msunsure 🔍
-7% - +2%
-0.84ms - +0.19ms
-faster ✔
1% - 10%
0.14ms - 1.10ms
previous-release
previous-release
11.11ms - 11.71msunsure 🔍
-2% - +7%
-0.17ms - +0.77ms
slower ❌
1% - 10%
0.14ms - 1.10ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
33.28ms - 34.29ms-unsure 🔍
-3% - +1%
-1.19ms - +0.38ms
unsure 🔍
-3% - +1%
-1.13ms - +0.35ms
tip-of-tree
tip-of-tree
33.59ms - 34.78msunsure 🔍
-1% - +4%
-0.38ms - +1.19ms
-unsure 🔍
-2% - +2%
-0.79ms - +0.82ms
previous-release
previous-release
33.63ms - 34.71msunsure 🔍
-1% - +3%
-0.35ms - +1.13ms
unsure 🔍
-2% - +2%
-0.82ms - +0.79ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
71.22ms - 74.20ms-unsure 🔍
-6% - +1%
-4.20ms - +0.56ms
unsure 🔍
-4% - +2%
-2.91ms - +1.64ms
tip-of-tree
tip-of-tree
72.68ms - 76.39msunsure 🔍
-1% - +6%
-0.56ms - +4.20ms
-unsure 🔍
-2% - +5%
-1.34ms - +3.72ms
previous-release
previous-release
71.63ms - 75.06msunsure 🔍
-2% - +4%
-1.64ms - +2.91ms
unsure 🔍
-5% - +2%
-3.72ms - +1.34ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
31.07ms - 31.94ms-unsure 🔍
-3% - +2%
-0.82ms - +0.52ms
unsure 🔍
-2% - +2%
-0.73ms - +0.63ms
tip-of-tree
tip-of-tree
31.15ms - 32.16msunsure 🔍
-2% - +3%
-0.52ms - +0.82ms
-unsure 🔍
-2% - +3%
-0.63ms - +0.83ms
previous-release
previous-release
31.03ms - 32.09msunsure 🔍
-2% - +2%
-0.63ms - +0.73ms
unsure 🔍
-3% - +2%
-0.83ms - +0.63ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
511.69ms - 526.19ms-unsure 🔍
-2% - +2%
-12.47ms - +9.33ms
unsure 🔍
-2% - +2%
-11.80ms - +10.37ms
tip-of-tree
tip-of-tree
512.37ms - 528.64msunsure 🔍
-2% - +2%
-9.33ms - +12.47ms
-unsure 🔍
-2% - +2%
-10.83ms - +12.54ms
previous-release
previous-release
511.26ms - 528.04msunsure 🔍
-2% - +2%
-10.37ms - +11.80ms
unsure 🔍
-2% - +2%
-12.54ms - +10.83ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
515.93ms - 530.39ms-unsure 🔍
-2% - +2%
-11.97ms - +9.34ms
unsure 🔍
-2% - +2%
-13.04ms - +8.35ms
tip-of-tree
tip-of-tree
516.66ms - 532.30msunsure 🔍
-2% - +2%
-9.34ms - +11.97ms
-unsure 🔍
-2% - +2%
-12.13ms - +10.07ms
previous-release
previous-release
517.63ms - 533.38msunsure 🔍
-2% - +2%
-8.35ms - +13.04ms
unsure 🔍
-2% - +2%
-10.07ms - +12.13ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

The size of lit-html.js and lit-core.min.js are as expected.

packages/labs/analyzer/src/lib/javascript/classes.ts Outdated Show resolved Hide resolved
) {
const name = node.expression.left.name.getText();
const name = statement.expression.left.name.getText();
Copy link
Collaborator

Choose a reason for hiding this comment

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

here and elsewhere: getText() is almost always a mistake to call outside of debug statements, because it exists on every node but doesn't have a reasonable value for a lot of them (and when called on artificial nodes that weren't in the original source code it may throw an error)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is already used in a bunch of places. I can file an issue to change them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, we should honestly add a lint rule to catch and prevent calls to getText(). We did that on the internal version of grimlock and it prevented a bunch of issues.

Andrew actually ran into an issue today where .getText() did the wrong thing (when called on a SourceFile it doesn't include all the content of the file (!), it misses leading comments. SourceFile has a .text property with the full text of the file)

Copy link
Contributor

Choose a reason for hiding this comment

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

image

packages/labs/analyzer/src/lib/model.ts Outdated Show resolved Hide resolved
Base automatically changed from 3.0 to main October 9, 2023 16:54
@justinfagnani justinfagnani changed the base branch from main to analyzer-nodes October 27, 2023 18:29
Base automatically changed from analyzer-nodes to main October 27, 2023 22:33
Copy link
Collaborator

@rictic rictic left a comment

Choose a reason for hiding this comment

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

LGTM, but for reals, every .getText() is a bug waiting to happen

@justinfagnani justinfagnani merged commit 1b17a36 into main Feb 1, 2024
9 checks passed
@justinfagnani justinfagnani deleted the analyzer-templates branch February 1, 2024 17:34
@lit-robot lit-robot mentioned this pull request Mar 11, 2024
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