Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Jun 28, 2023

Issue: #189
RFC: lit/rfcs#21

lit-labs/compiler

This commit adds a first (and rough) iteration of the Lit compiler for pre-compiling html TTLs. This change passes almost all lit-html tests.

The skipped tests are:

  • Some dev mode warnings, which currently get compiled out. Should instead become diagnostics.
  • The cache directive depends on a template string array & needs handling added for compiled templates.

This initial change was used for benchmarking the possible benefits of the compiler.

No changeset is included because the package is marked private and will not be released.

Why

lit-html is very fast, but if you're already using a build step there are opportunities to squeeze more performance out. By pre-compiling templates, we can skip the prepare phase of lit-html rendering.

Benchmarks

The below benchmarks can be run by checking out this branch, building the monorepo and running individual benchmarks e.g., npm run benchmark:lit-html:template-heavy-compiled -w @lit-internal/benchmarks.

Kitchen sink average tachometer benchmark results:

  • [6.7% faster]: render-compiled: 7.93ms - 8.10ms, render-uncompiled: 8.50ms - 8.69ms
  • [roughly same]: update-compiled: 17.92ms - 18.56ms, update-uncompiled: 18.08ms - 19.00ms
  • [roughly same]: nop-update-compiled: 5.53ms - 5.66ms, nop-update-uncompiled: 5.64ms - 5.80ms

Template Heavy average tachometer benchmark results:

  • [46% faster]: render-compiled: 9.51ms - 9.67ms, render-uncompiled: 17.66ms - 18.03ms
  • [21% faster]: update-compiled: 26.40 - 26.91ms, update-uncompiled: 33.62 - 34.51ms

repeat average tachometer benchmark results:

  • [14% faster]: render-compiled: 7.40ms - 7.62ms, render-uncompiled: 8.56ms - 8.94ms
  • [8% faster]: update-compiled: 189.57ms - 197.54ms, update-uncompiled: 206.51ms - 218.68ms

TODO:

  • Fix wireit config
  • cleanup
  • docs
  • hook up benchmarks
  • Add sourcemap tests
  • Add lit-element tests
  • add RFC to figure out public API.

@changeset-bot
Copy link

changeset-bot bot commented Jun 28, 2023

🦋 Changeset detected

Latest commit: 84b68eb

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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 Jun 28, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • lit-html-kitchen-sink: unsure 🔍 -11% - +9% (-3.33ms - +2.72ms)
    this-change vs tip-of-tree

render

  • lit-element-list: 93.49ms - 98.56ms
  • lit-html-kitchen-sink: unsure 🔍 -8% - +6% (-3.29ms - +2.19ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -10% - +4% (-1.27ms - +0.54ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -3% - +4% (-1.76ms - +2.67ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -3% - +5% (-1.94ms - +2.88ms)
    this-change vs tip-of-tree

update

  • lit-element-list: 1081.65ms - 1124.23ms
  • lit-html-kitchen-sink: unsure 🔍 -5% - +4% (-5.86ms - +4.63ms)
    this-change vs tip-of-tree
  • lit-html-repeat: unsure 🔍 -10% - +11% (-42.45ms - +44.70ms)
    this-change vs tip-of-tree
  • lit-html-template-heavy: unsure 🔍 -2% - +3% (-2.52ms - +5.32ms)
    this-change vs tip-of-tree
  • reactive-element-list: unsure 🔍 -0% - +4% (-5.23ms - +44.19ms)
    this-change vs tip-of-tree

update-reflect

  • lit-element-list: 1005.94ms - 1042.04ms
  • reactive-element-list: unsure 🔍 -1% - +4% (-12.94ms - +39.70ms)
    this-change vs tip-of-tree

Results

lit-element-list

render

VersionAvg timevs
93.49ms - 98.56ms-

update

VersionAvg timevs
1081.65ms - 1124.23ms-

update-reflect

VersionAvg timevs
1005.94ms - 1042.04ms-
lit-html-kitchen-sink

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
36.46ms - 40.39ms-unsure 🔍
-8% - +6%
-3.29ms - +2.19ms
unsure 🔍
-11% - +3%
-4.25ms - +1.09ms
tip-of-tree
tip-of-tree
37.07ms - 40.88msunsure 🔍
-6% - +9%
-2.19ms - +3.29ms
-unsure 🔍
-9% - +4%
-3.66ms - +1.60ms
previous-release
previous-release
38.20ms - 41.82msunsure 🔍
-3% - +11%
-1.09ms - +4.25ms
unsure 🔍
-4% - +9%
-1.60ms - +3.66ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
105.52ms - 113.86ms-unsure 🔍
-5% - +4%
-5.86ms - +4.63ms
unsure 🔍
-8% - +2%
-8.62ms - +2.30ms
tip-of-tree
tip-of-tree
107.13ms - 113.49msunsure 🔍
-4% - +5%
-4.63ms - +5.86ms
-unsure 🔍
-6% - +2%
-7.29ms - +2.21ms
previous-release
previous-release
109.32ms - 116.37msunsure 🔍
-2% - +8%
-2.30ms - +8.62ms
unsure 🔍
-2% - +7%
-2.21ms - +7.29ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
27.06ms - 31.07ms-unsure 🔍
-11% - +9%
-3.33ms - +2.72ms
unsure 🔍
-7% - +13%
-2.03ms - +3.63ms
tip-of-tree
tip-of-tree
27.10ms - 31.63msunsure 🔍
-9% - +12%
-2.72ms - +3.33ms
-unsure 🔍
-7% - +15%
-1.91ms - +4.13ms
previous-release
previous-release
26.26ms - 30.26msunsure 🔍
-12% - +7%
-3.63ms - +2.03ms
unsure 🔍
-14% - +6%
-4.13ms - +1.91ms
-
lit-html-repeat

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
11.80ms - 13.09ms-unsure 🔍
-10% - +4%
-1.27ms - +0.54ms
unsure 🔍
-9% - +4%
-1.18ms - +0.56ms
tip-of-tree
tip-of-tree
12.17ms - 13.45msunsure 🔍
-4% - +10%
-0.54ms - +1.27ms
-unsure 🔍
-6% - +7%
-0.81ms - +0.92ms
previous-release
previous-release
12.17ms - 13.34msunsure 🔍
-5% - +10%
-0.56ms - +1.18ms
unsure 🔍
-7% - +6%
-0.92ms - +0.81ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
378.94ms - 446.70ms-unsure 🔍
-10% - +11%
-42.45ms - +44.70ms
unsure 🔍
-10% - +11%
-42.85ms - +44.65ms
tip-of-tree
tip-of-tree
384.29ms - 439.10msunsure 🔍
-11% - +10%
-44.70ms - +42.45ms
-unsure 🔍
-10% - +9%
-39.18ms - +38.72ms
previous-release
previous-release
384.25ms - 439.60msunsure 🔍
-11% - +10%
-44.65ms - +42.85ms
unsure 🔍
-9% - +10%
-38.72ms - +39.18ms
-
lit-html-template-heavy

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
64.69ms - 68.03ms-unsure 🔍
-3% - +4%
-1.76ms - +2.67ms
unsure 🔍
-4% - +2%
-2.90ms - +1.52ms
tip-of-tree
tip-of-tree
64.45ms - 67.36msunsure 🔍
-4% - +3%
-2.67ms - +1.76ms
-unsure 🔍
-5% - +1%
-3.20ms - +0.90ms
previous-release
previous-release
65.60ms - 68.50msunsure 🔍
-2% - +4%
-1.52ms - +2.90ms
unsure 🔍
-1% - +5%
-0.90ms - +3.20ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
151.45ms - 157.67ms-unsure 🔍
-2% - +3%
-2.52ms - +5.32ms
unsure 🔍
-2% - +3%
-2.97ms - +5.12ms
tip-of-tree
tip-of-tree
150.78ms - 155.54msunsure 🔍
-3% - +2%
-5.32ms - +2.52ms
-unsure 🔍
-3% - +2%
-3.84ms - +3.19ms
previous-release
previous-release
150.90ms - 156.08msunsure 🔍
-3% - +2%
-5.12ms - +2.97ms
unsure 🔍
-2% - +3%
-3.19ms - +3.84ms
-
reactive-element-list

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
57.54ms - 60.53ms-unsure 🔍
-3% - +5%
-1.94ms - +2.88ms
unsure 🔍
-8% - +0%
-5.27ms - +0.09ms
tip-of-tree
tip-of-tree
56.67ms - 60.45msunsure 🔍
-5% - +3%
-2.88ms - +1.94ms
-faster ✔
0% - 10%
0.15ms - 5.98ms
previous-release
previous-release
59.40ms - 63.85msunsure 🔍
-0% - +9%
-0.09ms - +5.27ms
slower ❌
0% - 10%
0.15ms - 5.98ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1101.65ms - 1138.45ms-unsure 🔍
-0% - +4%
-5.23ms - +44.19ms
unsure 🔍
-2% - +3%
-16.94ms - +31.70ms
tip-of-tree
tip-of-tree
1084.07ms - 1117.07msunsure 🔍
-4% - +0%
-44.19ms - +5.23ms
-unsure 🔍
-3% - +1%
-35.02ms - +10.82ms
previous-release
previous-release
1096.77ms - 1128.57msunsure 🔍
-3% - +2%
-31.70ms - +16.94ms
unsure 🔍
-1% - +3%
-10.82ms - +35.02ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1058.24ms - 1098.24ms-unsure 🔍
-1% - +4%
-12.94ms - +39.70ms
unsure 🔍
-3% - +2%
-28.06ms - +23.96ms
tip-of-tree
tip-of-tree
1047.75ms - 1081.96msunsure 🔍
-4% - +1%
-39.70ms - +12.94ms
-unsure 🔍
-4% - +1%
-39.28ms - +8.43ms
previous-release
previous-release
1063.65ms - 1096.91msunsure 🔍
-2% - +3%
-23.96ms - +28.06ms
unsure 🔍
-1% - +4%
-8.43ms - +39.28ms
-

tachometer-reporter-action v2 for Benchmarks

AndrewJakubowicz and others added 12 commits July 10, 2023 16:51
Current method is just to import all the Part constructors if any of
them are needed. But an identifier that already exists breaks tests.

As a stopgap have named them with an unlikely prefix.
After building, run benchmark with:
`npm run benchmark:lit-html:kitchen-sink-compiled -w @lit-internal/benchmarks`
Found one test where stripping the expression markers broke the test
between compiled and uncompiled. If that's a problem we may need to
emit a fake marker, e.g. lit$1$, to prevent test breakages.
@AndrewJakubowicz
Copy link
Contributor Author

This prototype was incrementally improved and landed. See all the linked PRs.

@AndrewJakubowicz AndrewJakubowicz deleted the initial-labs-compiler branch August 18, 2023 20:22
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.

1 participant