Skip to content

fix: Sleuth.track adds nothing to a release build - #32

Merged
Harrys76 merged 2 commits into
mainfrom
fix/release-tree-shaking
Oct 27, 2026
Merged

Harrys76 merged 2 commits into
mainfrom
fix/release-tree-shaking

Conversation

@Harrys76

@Harrys76 Harrys76 commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Sleuth.track promised to cost nothing in release builds. It added about 0.6 MB of code that never ran.

This branch reached main through #33, which was based on it. #33's merge commit is 3cc4e49, and GitHub marked this PR merged when its head commit landed on main. CI passed here and on #33.

Cause. track returned early with if (kReleaseMode) return child; and built the overlay after that line. The release compiler dropped all but about 1 KB of Sleuth's own code. It still kept the Flutter framework code the overlay uses: widgets, rendering, material, cupertino and text-input services.

Fix. The overlay path is now inside if (!kReleaseMode) { ... }, a branch the compiler drops whole, and track returns child after it. A comment at the branch says why it has this shape.

The other Sleuth statics keep their early returns. They reach the package only through the controller that track creates. In a release build that controller is always null, so the calls cost nothing.

Measured. Each test app is the stock flutter create counter app, built in release mode with Flutter 3.47.6. The table compares Dart code size, libapp.so on Android arm64 and App.framework/App on iOS.

App Before After
No Sleuth 3,212,168 B (Android), 3,469,264 B (iOS) same
Sleuth.init() + Sleuth.track(child:) +589,824 B (Android), +693,504 B (iOS) +0 on both
Plus a SleuthConfig with an AI adapter and a custom detector, and calls to the baseline, export, route-health and resource-tracking APIs +720,896 B (Android) +65,536 B

The last row's 64 KB comes from objects the app's own code builds: the config, the adapter and the detector class.

Checks.

  • fvm flutter analyze: 0 issues.
  • fvm flutter test --exclude-tags benchmark: 5,109 passed, 5 skipped.
  • Format: clean.

Docs. CHANGELOG, doc/release_notes/1.0.0.md and CLAUDE.md each have a line on the fix, and #33 later shortened the CHANGELOG line. The README's setup section says that a release app with Sleuth.track is the same size as one without it, and that a SleuthConfig your code builds adds 64 KB with an AI adapter and a custom detector.

Release. 1.0.0 is not on pub.dev yet, so this fix ships in 1.0.0. The v1.0.0 tag still points at f169bf0 and needs to move to 3cc4e49, and the GitHub release text needs this fix and the dart fix note from #33.

🤖 Generated with Claude Code

Harrys76 and others added 2 commits October 27, 2026 19:14
Sleuth.track returned early with `if (kReleaseMode) return child;` and
built the overlay after it. The release compiler dropped Sleuth's own
code but kept the Flutter framework code the overlay uses: on the stock
counter app, 590 KB of Dart code on Android arm64 and 677 KB on iOS,
although none of it ran. The overlay path now sits inside
`if (!kReleaseMode)`, a branch the compiler drops whole, and the app's
Dart code is the same size with Sleuth.track as without it.

The other Sleuth statics reach the package only through the controller
that track creates, so their early returns now cost nothing as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Harrys76
Harrys76 merged commit abd756b into main Oct 27, 2026
6 checks passed
@Harrys76
Harrys76 deleted the fix/release-tree-shaking branch October 27, 2026 15:24
Harrys76 added a commit that referenced this pull request Oct 27, 2026
docs: 1.0.0 doc edits from #33, on the docs from #32
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