Repository navigation
fix: Sleuth.track adds nothing to a release build - #32
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sleuth.trackpromised 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.
trackreturned early withif (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, andtrackreturnschildafter it. A comment at the branch says why it has this shape.The other
Sleuthstatics keep their early returns. They reach the package only through the controller thattrackcreates. In a release build that controller is always null, so the calls cost nothing.Measured. Each test app is the stock
flutter createcounter app, built in release mode with Flutter 3.47.6. The table compares Dart code size,libapp.soon Android arm64 andApp.framework/Appon iOS.Sleuth.init()+Sleuth.track(child:)SleuthConfigwith an AI adapter and a custom detector, and calls to the baseline, export, route-health and resource-tracking APIsThe 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.Docs. CHANGELOG,
doc/release_notes/1.0.0.mdand 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 withSleuth.trackis the same size as one without it, and that aSleuthConfigyour 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.0tag still points at f169bf0 and needs to move to 3cc4e49, and the GitHub release text needs this fix and thedart fixnote from #33.🤖 Generated with Claude Code