Skip to content

Conversation

@johnsoncodehk
Copy link

@johnsoncodehk johnsoncodehk commented Jan 8, 2025

We are re-constructing surface APIs based on alien-signals to obtain performance improvements, now faster than most frameworks.

We intentionally relies on the alien-signals package rather than duplicating code in order to easily discover code specific to the signal proposal.

Regarding the differences in test results.

  • Prohibited contexts - allows writes during computed: The alien-signals algorithm is able to handle computed side effects, so the expected results in the test are now modified to the correct values.

  • type checks - checks types in methods: I'm not sure what I should do to make the current implementation pass these tests, but since this PR is for research purposes only, I don't think this test is worth solving, so I just skipped it. (resolved)

Chart:

image

@trueadm
Copy link

trueadm commented Jan 8, 2025

@NullVoxPopuli Did you add prohibited-contexts.test? Does this test need to be updated or is there a genuine issue here do you think?

@NullVoxPopuli
Copy link
Contributor

I did not add it -- it was implemented with the original spec -- but I did pull it out of a massive test file, as we need to be describing why tests exist, and what they're testing, and why that behavior is important.

It is def a behavior question about whether or not folks want to allow synchronous mutation while reading another value.

Personally, I don't think this is a good idea, as it prior-reads of the mutated state are now out of date, and if the consumer is entangled with the mutated state, that usually leads to infinite looping when a renderer is involved

@johnsoncodehk
Copy link
Author

We have already solved the problem of infinite loops at the algorithmic level. If synchronous mutations in computed is not handled, it can not pass the Vue core test suite.

@NullVoxPopuli
Copy link
Contributor

Sounds fine since it's solved.
Not sure if proposal text will need to update

@hybrist
Copy link

hybrist commented Jan 9, 2025

Can you link to the source of the benchmark? I'd be curious to see what the test setup was like. Was it based on https://github.com/transitive-bullshit/js-reactivity-benchmark?

johnsoncodehk added a commit to johnsoncodehk/js-reactivity-benchmark that referenced this pull request Jan 12, 2025
@johnsoncodehk
Copy link
Author

johnsoncodehk commented Jan 12, 2025

@jkrems yes, I just add a test for this PR to a new branch.

https://github.com/johnsoncodehk/js-reactivity-benchmark/tree/alien-polyfill

@hybrist
Copy link

hybrist commented Jan 13, 2025

@johnsoncodehk I was asking because that benchmark has some known measuring artifacts for the signal polyfill specifically (see https://x.com/synalx/status/1868235387812053167). So it might be less predictive for this particular PR. That doesn't mean that this PR isn't a performance improvement. But it might just require additional validation before it's clear how it compares.

@johnsoncodehk johnsoncodehk changed the title Experiment with building a proposal API on top of alien-signals Building a proposal API on top of alien-signals Jun 22, 2025
@jkup
Copy link

jkup commented Jun 25, 2025

Thank you so much for this work @johnsoncodehk! I believe @EisenbergEffect said offline he was also in favor of this general approach?

Does anyone have concerns about moving in this direction? I think maybe I had heard conversations where some application use cases found other approaches to be faster?

It's a large change so I'm hesitant for us to merge it in without a bit more conversation / consensus but would love to hear how people are feeling!

// would cause it to change value (due to the set inside of it).
expect(c.get()).toBe(2);
expect(s.get()).toBe(2);
if (isAlien) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when are we not alien?

Copy link
Author

Choose a reason for hiding this comment

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

It's always alien, this IF branch is just to demonstrate the difference between the old and new behavior.

src/alien.ts Outdated
@@ -0,0 +1,360 @@
import * as alien from 'alien-signals';
Copy link
Contributor

Choose a reason for hiding this comment

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

do we get any perf benefits by internalizing the implementation here?

Copy link
Author

Choose a reason for hiding this comment

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

Depending on how much internalizing can simplify the alien's createReactiveSystem abstraction. Based on my experience internalizing alien into Vue, the potential performance improvement is likely negligible (<5%).

@JuerGenie
Copy link

JuerGenie commented Jul 21, 2025

Hi, any updates? Can't wait to see the new stuff! :D

I think using alien-signals for this proposal (or other reactivity systems) is perfect because it:


  • It's lightweight & simple, super easy to work with!
  • We can share these polyfills across projects using alien-signals (or similar systems based on it), saving us from maintaining multiple reactivity tools + bridge layers.
  • When this proposal becomes standard, we could just wrap the reactivity layer with a compatibility API. Projects upgrade seamlessly!

Unifying reactivity systems at this level would be fantastic! Big thanks for your awesome work! 🤗

@johnsoncodehk johnsoncodehk marked this pull request as draft August 12, 2025 07:50
@johnsoncodehk

This comment was marked as resolved.

@johnsoncodehk johnsoncodehk marked this pull request as ready for review August 12, 2025 11:21
@johnsoncodehk
Copy link
Author

I think the PR is complete!

The implementation has been simplified a lot while maintaining as much consistency as possible with the original behavior. To achieve this, surface APIs have added checks for isState, isComputed, and isWatcher, which will affect performance. The initial performance comparison may no longer be applicable, but the improvements should still be significant.

@johnsoncodehk johnsoncodehk changed the title Building a proposal API on top of alien-signals Building the proposal API on top of alien-signals Aug 12, 2025
@johnsoncodehk johnsoncodehk changed the title Building the proposal API on top of alien-signals Build the proposal API on top of alien-signals Aug 12, 2025
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.

9 participants