Visitar URL original
Some more cleanups & fixes by parenthetical · Pull Request #557 · reflex-frp/reflex · GitHub
Skip to content

Some more cleanups & fixes - #557

Open
parenthetical wants to merge 49 commits into
developfrom
alns/2026-10-21-many-changes
Open

parenthetical wants to merge 49 commits into
developfrom
alns/2026-10-21-many-changes

Conversation

@parenthetical

Copy link
Copy Markdown
Contributor

No description provided.

…ightBag

IntMap.size is O(n), so the code in merges comparing the number of
parents (n) with the number of entries in the merge's HeightBag could be
slow on wide merges, with a worst case O(n^2) if every parent changed
height. Solved it structurally by changing how HeightBag works. The
latter now stores the number of invalidated merge parents and the
earlier comparison is no longer needed.

Even non mergeInt merges are now a little bit more efficient I believe.
After a merge was unsubscribed from, it would still subscribe to a new
parent arriving via the incremental update change event. This could
cause a useless pair of subscribe and unsubscribes (unsubscribing when
the GC collected the new subscription).

Also removed the retained subscribe function in merge which was not
needed, saving a few bytes.
`runFrame` collects the switches to reconnect before it updates merges,
and reconnects them after. If a finalizer unsubscribes a switch in
between, the switch would still subscribe to its new parent, and stay
subscribed until the GC collected it. The old parent would also get
unsubscribed twice.

To fix, the switch's current parent ref now has an unsubscribed state, and runFrame
skips switches in that state.
It was only used to finalize the weak invalidator when a switch is
unsubscribed, so that a later hold change can't put the switch back into
toReconnect. runFrame skips unsubscribed switches now, so we don't need
that. Finalizing it again in the reconnect loop did nothing, since
invalidate already finalizes it.

Saves an IORef per switch subscription.
Focused.fans was defined but missing from the list of cases, so no
benchmark measured firing through fan and fanInt. Also drop the trailing
spaces from two of its names.
Fan now works like cacheEvent, where only the subscribers have a strong
reference to the fan state and no finalizer is needed to allow the
fan's parent and further up to be garbage collected.

Also fixes a race condition between the finalizer thread and the
frame-running thread, by making sure that the whole per-key subscriber
map is manipulated atomically.
It's a little bit more efficient.
Root events contained races between the finalizer thread and the frame
thread on the rootSubscribed map. A subscriber added during a teardown
would never fire, and map updates could get lost.

Map updates are now atomic and a teardown deletes only its own entry. An
MVar per setup makes the setups and teardowns of a key alternate.

Root events are now structured similarly to fans as well, making the
code more uniform.
@ymeister

ymeister commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Could you add https://github.com/obsidiansystems/style.hs while at it, please?

fourmolu formats the code between CPP directives as separate top-level
parts, so a conditional inside a declaration either fails to parse.
subrepo:
  subdir:   "style.hs"
  merged:   "417c71ee"
upstream:
  origin:   "git@github.com:obsidiansystems/style.hs.git"
  branch:   "main"
  commit:   "417c71ee"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
@parenthetical
parenthetical force-pushed the alns/2026-10-21-many-changes branch from 001ca4c to 93e930f Compare November 8, 2026 20:40
extra-substituters = https://nixcache.reflex-frp.org
extra-trusted-public-keys = ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=
- name: Check formatting
run: git ls-files -z '*.hs' | xargs -0 nix run ./style.hs -- --mode check

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIRC, this only runs fourmolu check, not hlint

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.

2 participants