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

Implement Effect, Computed and Signal classes as ES5 classes #160

Merged
merged 4 commits into from
Sep 18, 2022
Merged

Conversation

jviide
Copy link
Contributor

@jviide jviide commented Sep 16, 2022

This pull request implements the Effect, Computed and Signal classes as ES5 classes.

Added a workaround for a weird performance cliff that I encountered with Node.js 18.9.0. The workaround itself is in commit 64d0ab0. For some reason the TypeScript compiled version was faster than the hand-rolled ES5 classes when running this benchmark:

import * as core from "@/preact/signals-core";

{
  const count = core.signal(0);
  const double = core.computed(() => count.value * 2);
  core.effect(() => double.value + count.value);
  core.effect(() => double.value + count.value);
  core.effect(() => double.value + count.value);

  console.time("core");

  for (let i = 0; i < 20000000; i++) {
    count.value++;
    double.value;
  }

  console.timeEnd("core");
}

In the end it turned out that TypeScript wrapped the Computed prototype definitions into an IIFE. Adding that same IIFE to the hand-rolled ES5 version boosted the performance back to TypeScript-compiled levels 🫠

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2022

⚠️ No Changeset found

Latest commit: 64d0ab0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

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

Click here to learn what changesets are, and how to add one.

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

Base automatically changed from setless-core to main September 16, 2022 14:44
@netlify
Copy link

netlify bot commented Sep 16, 2022

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 64d0ab0
🔍 Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/63270737209c690008ef0ffa
😎 Deploy Preview https://deploy-preview-160--preact-signals-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2022

Size Change: -180 B (0%)

Total Size: 67.5 kB

Filename Size Change
docs/dist/assets/client.********.js 45.8 kB +1 B (0%)
docs/dist/assets/index.********.js 1.08 kB +243 B (+29%) 🚨
docs/dist/assets/signals-core.module.********.js 1.35 kB -246 B (-15%) 👏
docs/dist/assets/signals.module.********.js 1.97 kB -5 B (0%)
docs/dist/basic-********.js 246 B +1 B (0%)
docs/dist/demos-********.js 3.35 kB +3 B (0%)
docs/dist/nesting-********.js 1.13 kB +2 B (0%)
docs/dist/react-********.js 240 B +1 B (0%)
packages/core/dist/signals-core.js 1.38 kB -235 B (-15%) 👏
packages/core/dist/signals-core.mjs 1.39 kB +55 B (+4%)
ℹ️ View Unchanged
Filename Size
docs/dist/assets/jsxRuntime.module.********.js 282 B
docs/dist/assets/preact.module.********.js 4 kB
docs/dist/assets/style.********.js 21 B
docs/dist/assets/style.********.css 1.21 kB
packages/preact/dist/signals.js 1.2 kB
packages/preact/dist/signals.mjs 1.18 kB
packages/react/dist/signals.js 860 B
packages/react/dist/signals.mjs 840 B

compressed-size-action

@marvinhagemeister
Copy link
Member

The test failure is caused by a bug in babel's typescript plugin. Filed an issue there: babel/babel#14945

@marvinhagemeister
Copy link
Member

@jviide This should be ready to be merged once rebased. CI passes locally 🎉

@jviide jviide merged commit b2642d0 into main Sep 18, 2022
@jviide jviide deleted the es5-ify branch September 18, 2022 12:01
@gamedevsam
Copy link

Doesn't this reveal a problem with Node v18 though? Seems very strange and not at all what I'd expect. @mcollina this make sense at all to you?

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.

3 participants