Skip to content

perf: MagicPerfHooks, zone-carried causes, AuthRestored.changed, change-only repository notifies - #210

Merged
anilcancakir merged 7 commits into
masterfrom
feat/llm-perf-tracing
Sep 29, 2026
Merged

anilcancakir merged 7 commits into
masterfrom
feat/llm-perf-tracing

Conversation

@anilcancakir

Copy link
Copy Markdown
Member

What

  • MagicPerfHooks.sink with per-request ids replaces onRefreshUI; the notify cause is carried in the zone (root sites timerTick and broadcast, derived sites inherit).
  • Model.casts defaults to a const map; the stub, docs and skills write const casts.
  • AuthRestored.changed: false when the background user sync only confirmed the cached user.
  • Repository.patch, upsertFromShow and upsertFromList notify only when the cache changed.

Why

  • The perf report needs to name the site that started a rebuild, across awaits.
  • In uptizm every boot remounted the whole app a second after the Router mounted (magic_starter reloads on AuthRestored), tearing down any overlay or toast; one manual check rebuilt a hidden list several times through notifies that changed nothing.

Testing

  • flutter test green (2262); magic_starter (1660), magic_devtools (135) and uptizm (bin/check flutter) green against this branch.

Release before magic_starter, which needs AuthRestored.changed.

A timer tick and a broadcast handler open a root cause scope that replaces
the inherited one, and setState/repository queries inherit it, so a record
names the site that started the work. Model.casts defaults to a const map
and the model stub, docs and skills write const casts, so a cast map is no
longer rebuilt on every attribute read.
The background user sync dispatched AuthRestored on every 200, including
the cold-boot sync that only confirms the cached user, so a listener that
remounts on it (magic_starter's reload) rebuilt the whole app on every boot
and tore down whatever the user had just opened. AuthRestored gains
changed, false when the synced user serializes the same as the one held
before it; it defaults to true, so existing constructions keep their
meaning.
patch, upsertFromShow and upsertFromList notified on every call, so a
broadcast that restated a cached reading, or a refetch answering what was
already held, rebuilt every screen listening to the repository; in uptizm
one manual check rebuilt the hidden monitors list several times. Each write
now compares the raw stored attributes before and after (deep, map keys in
any order) and notifies only for a new, evicted or changed row. The deep
comparison moves out of BaseGuard into an internal sameValue helper both
use.
AuthRestored.changed compares toMap(), which drops hidden attributes, and
Repository.patch compares against a shallow copy, so a nested value changed
in place and patched back reads as unchanged. Both doc blocks now say so.
@codecov

codecov Bot commented Sep 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.25926% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/src/database/eloquent/model.dart 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kodizm

kodizm Bot commented Sep 29, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

I found no defects in this change, and CI is green.

I checked the areas most likely to go wrong:

  • patch: it takes its "before" copy from Model.attributes before merging. attributes returns a fresh shallow copy (model.dart:546), so a real change is still detected. The docs already cover the one case it misses: a nested map or list changed in place.
  • upsertFromList: it compares rows after carrying forward the show-only values, so a list page that leaves out a value the cache kept does not count as a change.
  • upsertFromShow: it still stores the new instance, so find returns the same object refresh did. Only the notification is skipped.
  • AuthRestored.changed: it is computed before setUser replaces the held user. It is true when no user was held. The constructor defaults it to true, so events built elsewhere keep their old meaning. base_guard.dart:558 is the only place the event is dispatched.
  • Zone-carried cause: _runInScope closes the scope when a returned Future completes, and otherwise in finally. Broadcast handlers stay inside the existing per-handler try/catch.
  • MagicPerfHooks.emit: if the sink throws, the error is caught and logged, and the notify still runs.
  • RunsActions: the old try/finally moved unchanged into _settle, so _runningKeys is still cleared.

With no sink installed, every instrumented site takes the old code path after one null check.

The repo's post-change sync (CLAUDE.md) is done: there are CHANGELOG.md entries under Unreleased (the onRefreshUI removal is marked BREAKING), doc/ pages, the model.stub update, and SKILL.md moves from 0.1.53 to 0.1.55.

I read the diffs for all changed lib/ files and for CHANGELOG.md. I did not read the new or changed test files or the doc/skill markdown line by line.

Tests

There are new tests in test/perf/magic_perf_hooks_test.dart, test/network/request_id_loopback_test.dart, and the repository, query, auth, model and controller tests. codecov reports 99.25% of the diff covered.

CI

  • Lint & Test: success
  • Generated code analyzes: success
  • Internal Links & Anchors: success
  • codecov/patch: success (99.25% of diff hit)
  • External Links: skipped
  • Auto-merge low-risk Dependabot PRs: skipped

@anilcancakir
anilcancakir merged commit 4474786 into master Sep 29, 2026
7 checks passed
@anilcancakir anilcancakir mentioned this pull request Sep 29, 2026
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