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

Simplify Node instances #233

Merged
merged 4 commits into from
Oct 7, 2022
Merged

Simplify Node instances #233

merged 4 commits into from
Oct 7, 2022

Conversation

jviide
Copy link
Contributor

@jviide jviide commented Oct 7, 2022

This pull request simplifies the Node objects used in the core by removing the Node._flags property:

  • The NODE_SUBSCRIBED flag was used only for making Signal._subscribe and Signal._unsubscribe idempotent. Turns out that _unsubscribe is idempotent regardless, and _subscribe can use an alternative check.
  • The NODE_FREE flag was used to mark Nodes for old dependencies just before recomputing/effects, and then to check whether those Nodes could be reused. The flag can be dropped if we use the Node._version property for a similar purpose, marking the Nodes for old dependencies by setting their _version value to -1. If a Node does get reused, then its _version after recompute/effect will be >= 0, so we can detect reused Nodes that way. I added a note to Signal._version that its values should always be >= 0, just to remind us in the future.

The end result is that the performance doesn't seem to suffer, Node instances take around 8% less memory (in my environment, using a supremely unscientific method of calculation), and there are some nice byte size savings.

jviide added 3 commits October 6, 2022 23:54
The flag can be replaced in ._subscribe with an alternative check
so that the method stays idempotent, and ._unsubscribe should be
idempotent without any additional checks.
Use Node._version === -1 to replace the NODE_FREE flag.
Use an early return for delicious byte savings.
@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2022

🦋 Changeset detected

Latest commit: 3f652a7

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

This PR includes changesets to release 1 package
Name Type
@preact/signals-core 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

@netlify
Copy link

netlify bot commented Oct 7, 2022

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 3f652a7
🔍 Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/6340064958b24f0008b051f5
😎 Deploy Preview https://deploy-preview-233--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 Oct 7, 2022

Size Change: -307 B (0%)

Total Size: 67.1 kB

Filename Size Change
docs/dist/assets/client.********.js 45.7 kB -1 B (0%)
docs/dist/assets/index.********.js 834 B -243 B (-23%) 🎉
docs/dist/assets/signals-core.module.********.js 1.34 kB -17 B (-1%)
docs/dist/assets/signals.module.********.js 1.97 kB -2 B (0%)
docs/dist/basic-********.js 244 B -1 B (0%)
docs/dist/demos-********.js 3.35 kB -2 B (0%)
docs/dist/nesting-********.js 1.13 kB -2 B (0%)
docs/dist/react-********.js 237 B -2 B (-1%)
packages/core/dist/signals-core.js 1.4 kB -17 B (-1%)
packages/core/dist/signals-core.mjs 1.43 kB -20 B (-1%)
ℹ️ 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.15 kB
packages/react/dist/signals.js 790 B
packages/react/dist/signals.mjs 764 B

compressed-size-action

@jviide jviide changed the title Simplify Node bookkeeping Simplify Node instances Oct 7, 2022
@jviide jviide merged commit dafa95b into main Oct 7, 2022
@jviide jviide deleted the simplificate-nodes branch October 7, 2022 12:15
@github-actions github-actions bot mentioned this pull request Oct 7, 2022
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