@wazir-dev/cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +111 -0
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/assets/composition-engine.mmd +34 -0
- package/assets/demo-script.sh +17 -0
- package/assets/logo-dark.svg +14 -0
- package/assets/logo.svg +14 -0
- package/assets/pipeline.mmd +39 -0
- package/assets/record-demo.sh +51 -0
- package/docs/README.md +51 -0
- package/docs/adapters/context-mode.md +60 -0
- package/docs/concepts/architecture.md +87 -0
- package/docs/concepts/artifact-model.md +60 -0
- package/docs/concepts/composition-engine.md +36 -0
- package/docs/concepts/indexing-and-recall.md +160 -0
- package/docs/concepts/observability.md +41 -0
- package/docs/concepts/roles-and-workflows.md +59 -0
- package/docs/concepts/terminology-policy.md +27 -0
- package/docs/getting-started/01-installation.md +78 -0
- package/docs/getting-started/02-first-run.md +102 -0
- package/docs/getting-started/03-adding-to-project.md +15 -0
- package/docs/getting-started/04-host-setup.md +15 -0
- package/docs/guides/ci-integration.md +15 -0
- package/docs/guides/creating-skills.md +15 -0
- package/docs/guides/expertise-module-authoring.md +15 -0
- package/docs/guides/hook-development.md +15 -0
- package/docs/guides/memory-and-learnings.md +34 -0
- package/docs/guides/multi-host-export.md +15 -0
- package/docs/guides/troubleshooting.md +101 -0
- package/docs/guides/writing-custom-roles.md +15 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-design.md +592 -0
- package/docs/plans/2026-03-15-cli-pipeline-integration-plan.md +598 -0
- package/docs/plans/2026-03-15-docs-enforcement-plan.md +238 -0
- package/docs/readmes/INDEX.md +99 -0
- package/docs/readmes/features/expertise/README.md +171 -0
- package/docs/readmes/features/exports/README.md +222 -0
- package/docs/readmes/features/hooks/README.md +103 -0
- package/docs/readmes/features/hooks/loop-cap-guard.md +133 -0
- package/docs/readmes/features/hooks/post-tool-capture.md +121 -0
- package/docs/readmes/features/hooks/post-tool-lint.md +130 -0
- package/docs/readmes/features/hooks/pre-compact-summary.md +122 -0
- package/docs/readmes/features/hooks/pre-tool-capture-route.md +100 -0
- package/docs/readmes/features/hooks/protected-path-write-guard.md +128 -0
- package/docs/readmes/features/hooks/session-start.md +119 -0
- package/docs/readmes/features/hooks/stop-handoff-harvest.md +125 -0
- package/docs/readmes/features/roles/README.md +157 -0
- package/docs/readmes/features/roles/clarifier.md +152 -0
- package/docs/readmes/features/roles/content-author.md +190 -0
- package/docs/readmes/features/roles/designer.md +193 -0
- package/docs/readmes/features/roles/executor.md +184 -0
- package/docs/readmes/features/roles/learner.md +210 -0
- package/docs/readmes/features/roles/planner.md +182 -0
- package/docs/readmes/features/roles/researcher.md +164 -0
- package/docs/readmes/features/roles/reviewer.md +184 -0
- package/docs/readmes/features/roles/specifier.md +162 -0
- package/docs/readmes/features/roles/verifier.md +215 -0
- package/docs/readmes/features/schemas/README.md +178 -0
- package/docs/readmes/features/skills/README.md +63 -0
- package/docs/readmes/features/skills/brainstorming.md +96 -0
- package/docs/readmes/features/skills/debugging.md +148 -0
- package/docs/readmes/features/skills/design.md +120 -0
- package/docs/readmes/features/skills/prepare-next.md +109 -0
- package/docs/readmes/features/skills/run-audit.md +159 -0
- package/docs/readmes/features/skills/scan-project.md +109 -0
- package/docs/readmes/features/skills/self-audit.md +176 -0
- package/docs/readmes/features/skills/tdd.md +137 -0
- package/docs/readmes/features/skills/using-skills.md +92 -0
- package/docs/readmes/features/skills/verification.md +120 -0
- package/docs/readmes/features/skills/writing-plans.md +104 -0
- package/docs/readmes/features/tooling/README.md +320 -0
- package/docs/readmes/features/workflows/README.md +186 -0
- package/docs/readmes/features/workflows/author.md +181 -0
- package/docs/readmes/features/workflows/clarify.md +154 -0
- package/docs/readmes/features/workflows/design-review.md +171 -0
- package/docs/readmes/features/workflows/design.md +169 -0
- package/docs/readmes/features/workflows/discover.md +162 -0
- package/docs/readmes/features/workflows/execute.md +173 -0
- package/docs/readmes/features/workflows/learn.md +167 -0
- package/docs/readmes/features/workflows/plan-review.md +165 -0
- package/docs/readmes/features/workflows/plan.md +170 -0
- package/docs/readmes/features/workflows/prepare-next.md +167 -0
- package/docs/readmes/features/workflows/review.md +169 -0
- package/docs/readmes/features/workflows/run-audit.md +191 -0
- package/docs/readmes/features/workflows/spec-challenge.md +159 -0
- package/docs/readmes/features/workflows/specify.md +160 -0
- package/docs/readmes/features/workflows/verify.md +177 -0
- package/docs/readmes/packages/README.md +50 -0
- package/docs/readmes/packages/ajv.md +117 -0
- package/docs/readmes/packages/context-mode.md +118 -0
- package/docs/readmes/packages/gray-matter.md +116 -0
- package/docs/readmes/packages/node-test.md +137 -0
- package/docs/readmes/packages/yaml.md +112 -0
- package/docs/reference/configuration-reference.md +159 -0
- package/docs/reference/expertise-index.md +52 -0
- package/docs/reference/git-flow.md +43 -0
- package/docs/reference/hooks.md +87 -0
- package/docs/reference/host-exports.md +50 -0
- package/docs/reference/launch-checklist.md +172 -0
- package/docs/reference/marketplace-listings.md +76 -0
- package/docs/reference/release-process.md +34 -0
- package/docs/reference/roles-reference.md +77 -0
- package/docs/reference/skills.md +33 -0
- package/docs/reference/templates.md +29 -0
- package/docs/reference/tooling-cli.md +94 -0
- package/docs/truth-claims.yaml +222 -0
- package/expertise/PROGRESS.md +63 -0
- package/expertise/README.md +18 -0
- package/expertise/antipatterns/PROGRESS.md +56 -0
- package/expertise/antipatterns/backend/api-design-antipatterns.md +1271 -0
- package/expertise/antipatterns/backend/auth-antipatterns.md +1195 -0
- package/expertise/antipatterns/backend/caching-antipatterns.md +622 -0
- package/expertise/antipatterns/backend/database-antipatterns.md +1038 -0
- package/expertise/antipatterns/backend/index.md +24 -0
- package/expertise/antipatterns/backend/microservices-antipatterns.md +850 -0
- package/expertise/antipatterns/code/architecture-antipatterns.md +919 -0
- package/expertise/antipatterns/code/async-antipatterns.md +622 -0
- package/expertise/antipatterns/code/code-smells.md +1186 -0
- package/expertise/antipatterns/code/dependency-antipatterns.md +1209 -0
- package/expertise/antipatterns/code/error-handling-antipatterns.md +1360 -0
- package/expertise/antipatterns/code/index.md +27 -0
- package/expertise/antipatterns/code/naming-and-abstraction.md +1118 -0
- package/expertise/antipatterns/code/state-management-antipatterns.md +1076 -0
- package/expertise/antipatterns/code/testing-antipatterns.md +1053 -0
- package/expertise/antipatterns/design/accessibility-antipatterns.md +1136 -0
- package/expertise/antipatterns/design/dark-patterns.md +1121 -0
- package/expertise/antipatterns/design/index.md +22 -0
- package/expertise/antipatterns/design/ui-antipatterns.md +1202 -0
- package/expertise/antipatterns/design/ux-antipatterns.md +680 -0
- package/expertise/antipatterns/frontend/css-layout-antipatterns.md +691 -0
- package/expertise/antipatterns/frontend/flutter-antipatterns.md +1827 -0
- package/expertise/antipatterns/frontend/index.md +23 -0
- package/expertise/antipatterns/frontend/mobile-antipatterns.md +573 -0
- package/expertise/antipatterns/frontend/react-antipatterns.md +1128 -0
- package/expertise/antipatterns/frontend/spa-antipatterns.md +1235 -0
- package/expertise/antipatterns/index.md +31 -0
- package/expertise/antipatterns/performance/index.md +20 -0
- package/expertise/antipatterns/performance/performance-antipatterns.md +1013 -0
- package/expertise/antipatterns/performance/premature-optimization.md +623 -0
- package/expertise/antipatterns/performance/scaling-antipatterns.md +785 -0
- package/expertise/antipatterns/process/ai-coding-antipatterns.md +853 -0
- package/expertise/antipatterns/process/code-review-antipatterns.md +656 -0
- package/expertise/antipatterns/process/deployment-antipatterns.md +920 -0
- package/expertise/antipatterns/process/index.md +23 -0
- package/expertise/antipatterns/process/technical-debt-antipatterns.md +647 -0
- package/expertise/antipatterns/security/index.md +20 -0
- package/expertise/antipatterns/security/secrets-antipatterns.md +849 -0
- package/expertise/antipatterns/security/security-theater.md +843 -0
- package/expertise/antipatterns/security/vulnerability-patterns.md +801 -0
- package/expertise/architecture/PROGRESS.md +70 -0
- package/expertise/architecture/data/caching-architecture.md +671 -0
- package/expertise/architecture/data/data-consistency.md +574 -0
- package/expertise/architecture/data/data-modeling.md +536 -0
- package/expertise/architecture/data/event-streams-and-queues.md +634 -0
- package/expertise/architecture/data/index.md +25 -0
- package/expertise/architecture/data/search-architecture.md +663 -0
- package/expertise/architecture/data/sql-vs-nosql.md +708 -0
- package/expertise/architecture/decisions/architecture-decision-records.md +640 -0
- package/expertise/architecture/decisions/build-vs-buy.md +616 -0
- package/expertise/architecture/decisions/index.md +23 -0
- package/expertise/architecture/decisions/monolith-to-microservices.md +790 -0
- package/expertise/architecture/decisions/technology-selection.md +616 -0
- package/expertise/architecture/distributed/cap-theorem-and-tradeoffs.md +800 -0
- package/expertise/architecture/distributed/circuit-breaker-bulkhead.md +741 -0
- package/expertise/architecture/distributed/consensus-and-coordination.md +796 -0
- package/expertise/architecture/distributed/distributed-systems-fundamentals.md +564 -0
- package/expertise/architecture/distributed/idempotency-and-retry.md +796 -0
- package/expertise/architecture/distributed/index.md +25 -0
- package/expertise/architecture/distributed/saga-pattern.md +797 -0
- package/expertise/architecture/foundations/architectural-thinking.md +460 -0
- package/expertise/architecture/foundations/coupling-and-cohesion.md +770 -0
- package/expertise/architecture/foundations/design-principles-solid.md +649 -0
- package/expertise/architecture/foundations/domain-driven-design.md +719 -0
- package/expertise/architecture/foundations/index.md +25 -0
- package/expertise/architecture/foundations/separation-of-concerns.md +472 -0
- package/expertise/architecture/foundations/twelve-factor-app.md +797 -0
- package/expertise/architecture/index.md +34 -0
- package/expertise/architecture/integration/api-design-graphql.md +638 -0
- package/expertise/architecture/integration/api-design-grpc.md +804 -0
- package/expertise/architecture/integration/api-design-rest.md +892 -0
- package/expertise/architecture/integration/index.md +25 -0
- package/expertise/architecture/integration/third-party-integration.md +795 -0
- package/expertise/architecture/integration/webhooks-and-callbacks.md +1152 -0
- package/expertise/architecture/integration/websockets-realtime.md +791 -0
- package/expertise/architecture/mobile-architecture/index.md +22 -0
- package/expertise/architecture/mobile-architecture/mobile-app-architecture.md +780 -0
- package/expertise/architecture/mobile-architecture/mobile-backend-for-frontend.md +670 -0
- package/expertise/architecture/mobile-architecture/offline-first.md +719 -0
- package/expertise/architecture/mobile-architecture/push-and-sync.md +782 -0
- package/expertise/architecture/patterns/cqrs-event-sourcing.md +717 -0
- package/expertise/architecture/patterns/event-driven.md +797 -0
- package/expertise/architecture/patterns/hexagonal-clean-architecture.md +870 -0
- package/expertise/architecture/patterns/index.md +27 -0
- package/expertise/architecture/patterns/layered-architecture.md +736 -0
- package/expertise/architecture/patterns/microservices.md +753 -0
- package/expertise/architecture/patterns/modular-monolith.md +692 -0
- package/expertise/architecture/patterns/monolith.md +626 -0
- package/expertise/architecture/patterns/plugin-architecture.md +735 -0
- package/expertise/architecture/patterns/serverless.md +780 -0
- package/expertise/architecture/scaling/database-scaling.md +615 -0
- package/expertise/architecture/scaling/feature-flags-and-rollouts.md +757 -0
- package/expertise/architecture/scaling/horizontal-vs-vertical.md +606 -0
- package/expertise/architecture/scaling/index.md +24 -0
- package/expertise/architecture/scaling/multi-tenancy.md +800 -0
- package/expertise/architecture/scaling/stateless-design.md +787 -0
- package/expertise/backend/embedded-firmware.md +625 -0
- package/expertise/backend/go.md +853 -0
- package/expertise/backend/index.md +24 -0
- package/expertise/backend/java-spring.md +448 -0
- package/expertise/backend/node-typescript.md +625 -0
- package/expertise/backend/python-fastapi.md +724 -0
- package/expertise/backend/rust.md +458 -0
- package/expertise/backend/solidity.md +711 -0
- package/expertise/composition-map.yaml +443 -0
- package/expertise/content/foundations/content-modeling.md +395 -0
- package/expertise/content/foundations/editorial-standards.md +449 -0
- package/expertise/content/foundations/index.md +24 -0
- package/expertise/content/foundations/microcopy.md +455 -0
- package/expertise/content/foundations/terminology-governance.md +509 -0
- package/expertise/content/index.md +34 -0
- package/expertise/content/patterns/accessibility-copy.md +518 -0
- package/expertise/content/patterns/index.md +24 -0
- package/expertise/content/patterns/notification-content.md +433 -0
- package/expertise/content/patterns/sample-content.md +486 -0
- package/expertise/content/patterns/state-copy.md +439 -0
- package/expertise/design/PROGRESS.md +58 -0
- package/expertise/design/disciplines/dark-mode-theming.md +577 -0
- package/expertise/design/disciplines/design-systems.md +595 -0
- package/expertise/design/disciplines/index.md +25 -0
- package/expertise/design/disciplines/information-architecture.md +800 -0
- package/expertise/design/disciplines/interaction-design.md +788 -0
- package/expertise/design/disciplines/responsive-design.md +552 -0
- package/expertise/design/disciplines/usability-testing.md +516 -0
- package/expertise/design/disciplines/user-research.md +792 -0
- package/expertise/design/foundations/accessibility-design.md +796 -0
- package/expertise/design/foundations/color-theory.md +797 -0
- package/expertise/design/foundations/iconography.md +795 -0
- package/expertise/design/foundations/index.md +26 -0
- package/expertise/design/foundations/motion-and-animation.md +653 -0
- package/expertise/design/foundations/rtl-design.md +585 -0
- package/expertise/design/foundations/spacing-and-layout.md +607 -0
- package/expertise/design/foundations/typography.md +800 -0
- package/expertise/design/foundations/visual-hierarchy.md +761 -0
- package/expertise/design/index.md +32 -0
- package/expertise/design/patterns/authentication-flows.md +474 -0
- package/expertise/design/patterns/content-consumption.md +789 -0
- package/expertise/design/patterns/data-display.md +618 -0
- package/expertise/design/patterns/e-commerce.md +1494 -0
- package/expertise/design/patterns/feedback-and-states.md +642 -0
- package/expertise/design/patterns/forms-and-input.md +819 -0
- package/expertise/design/patterns/gamification.md +801 -0
- package/expertise/design/patterns/index.md +31 -0
- package/expertise/design/patterns/microinteractions.md +449 -0
- package/expertise/design/patterns/navigation.md +800 -0
- package/expertise/design/patterns/notifications.md +705 -0
- package/expertise/design/patterns/onboarding.md +700 -0
- package/expertise/design/patterns/search-and-filter.md +601 -0
- package/expertise/design/patterns/settings-and-preferences.md +768 -0
- package/expertise/design/patterns/social-and-community.md +748 -0
- package/expertise/design/platforms/desktop-native.md +612 -0
- package/expertise/design/platforms/index.md +25 -0
- package/expertise/design/platforms/mobile-android.md +825 -0
- package/expertise/design/platforms/mobile-cross-platform.md +983 -0
- package/expertise/design/platforms/mobile-ios.md +699 -0
- package/expertise/design/platforms/tablet.md +794 -0
- package/expertise/design/platforms/web-dashboard.md +790 -0
- package/expertise/design/platforms/web-responsive.md +550 -0
- package/expertise/design/psychology/behavioral-nudges.md +449 -0
- package/expertise/design/psychology/cognitive-load.md +1191 -0
- package/expertise/design/psychology/error-psychology.md +778 -0
- package/expertise/design/psychology/index.md +22 -0
- package/expertise/design/psychology/persuasive-design.md +736 -0
- package/expertise/design/psychology/user-mental-models.md +623 -0
- package/expertise/design/tooling/open-pencil.md +266 -0
- package/expertise/frontend/angular.md +1073 -0
- package/expertise/frontend/desktop-electron.md +546 -0
- package/expertise/frontend/flutter.md +782 -0
- package/expertise/frontend/index.md +27 -0
- package/expertise/frontend/native-android.md +409 -0
- package/expertise/frontend/native-ios.md +490 -0
- package/expertise/frontend/react-native.md +1160 -0
- package/expertise/frontend/react.md +808 -0
- package/expertise/frontend/vue.md +1089 -0
- package/expertise/humanize/domain-rules-code.md +79 -0
- package/expertise/humanize/domain-rules-content.md +67 -0
- package/expertise/humanize/domain-rules-technical-docs.md +56 -0
- package/expertise/humanize/index.md +35 -0
- package/expertise/humanize/self-audit-checklist.md +87 -0
- package/expertise/humanize/sentence-patterns.md +218 -0
- package/expertise/humanize/vocabulary-blacklist.md +105 -0
- package/expertise/i18n/PROGRESS.md +65 -0
- package/expertise/i18n/advanced/accessibility-and-i18n.md +28 -0
- package/expertise/i18n/advanced/bidirectional-text-algorithm.md +38 -0
- package/expertise/i18n/advanced/complex-scripts.md +30 -0
- package/expertise/i18n/advanced/performance-and-i18n.md +27 -0
- package/expertise/i18n/advanced/testing-i18n.md +28 -0
- package/expertise/i18n/content/content-adaptation.md +23 -0
- package/expertise/i18n/content/locale-specific-formatting.md +23 -0
- package/expertise/i18n/content/machine-translation-integration.md +28 -0
- package/expertise/i18n/content/translation-management.md +29 -0
- package/expertise/i18n/foundations/date-time-calendars.md +67 -0
- package/expertise/i18n/foundations/i18n-architecture.md +272 -0
- package/expertise/i18n/foundations/locale-and-language-tags.md +79 -0
- package/expertise/i18n/foundations/numbers-currency-units.md +61 -0
- package/expertise/i18n/foundations/pluralization-and-gender.md +109 -0
- package/expertise/i18n/foundations/string-externalization.md +236 -0
- package/expertise/i18n/foundations/text-direction-bidi.md +241 -0
- package/expertise/i18n/foundations/unicode-and-encoding.md +86 -0
- package/expertise/i18n/index.md +38 -0
- package/expertise/i18n/platform/backend-i18n.md +31 -0
- package/expertise/i18n/platform/flutter-i18n.md +148 -0
- package/expertise/i18n/platform/native-android-i18n.md +36 -0
- package/expertise/i18n/platform/native-ios-i18n.md +36 -0
- package/expertise/i18n/platform/react-i18n.md +103 -0
- package/expertise/i18n/platform/web-css-i18n.md +81 -0
- package/expertise/i18n/rtl/arabic-specific.md +175 -0
- package/expertise/i18n/rtl/hebrew-specific.md +149 -0
- package/expertise/i18n/rtl/rtl-animations-and-transitions.md +111 -0
- package/expertise/i18n/rtl/rtl-forms-and-input.md +161 -0
- package/expertise/i18n/rtl/rtl-fundamentals.md +211 -0
- package/expertise/i18n/rtl/rtl-icons-and-images.md +181 -0
- package/expertise/i18n/rtl/rtl-layout-mirroring.md +252 -0
- package/expertise/i18n/rtl/rtl-navigation-and-gestures.md +107 -0
- package/expertise/i18n/rtl/rtl-testing-and-qa.md +147 -0
- package/expertise/i18n/rtl/rtl-typography.md +160 -0
- package/expertise/index.md +113 -0
- package/expertise/index.yaml +216 -0
- package/expertise/infrastructure/cloud-aws.md +597 -0
- package/expertise/infrastructure/cloud-gcp.md +599 -0
- package/expertise/infrastructure/cybersecurity.md +816 -0
- package/expertise/infrastructure/database-mongodb.md +447 -0
- package/expertise/infrastructure/database-postgres.md +400 -0
- package/expertise/infrastructure/devops-cicd.md +787 -0
- package/expertise/infrastructure/index.md +27 -0
- package/expertise/performance/PROGRESS.md +50 -0
- package/expertise/performance/backend/api-latency.md +1204 -0
- package/expertise/performance/backend/background-jobs.md +506 -0
- package/expertise/performance/backend/connection-pooling.md +1209 -0
- package/expertise/performance/backend/database-query-optimization.md +515 -0
- package/expertise/performance/backend/index.md +23 -0
- package/expertise/performance/backend/rate-limiting-and-throttling.md +971 -0
- package/expertise/performance/foundations/algorithmic-complexity.md +954 -0
- package/expertise/performance/foundations/caching-strategies.md +489 -0
- package/expertise/performance/foundations/concurrency-and-parallelism.md +847 -0
- package/expertise/performance/foundations/index.md +24 -0
- package/expertise/performance/foundations/measuring-and-profiling.md +440 -0
- package/expertise/performance/foundations/memory-management.md +964 -0
- package/expertise/performance/foundations/performance-budgets.md +1314 -0
- package/expertise/performance/index.md +31 -0
- package/expertise/performance/infrastructure/auto-scaling.md +1059 -0
- package/expertise/performance/infrastructure/cdn-and-edge.md +1081 -0
- package/expertise/performance/infrastructure/index.md +22 -0
- package/expertise/performance/infrastructure/load-balancing.md +1081 -0
- package/expertise/performance/infrastructure/observability.md +1079 -0
- package/expertise/performance/mobile/index.md +23 -0
- package/expertise/performance/mobile/mobile-animations.md +544 -0
- package/expertise/performance/mobile/mobile-memory-battery.md +416 -0
- package/expertise/performance/mobile/mobile-network.md +452 -0
- package/expertise/performance/mobile/mobile-rendering.md +599 -0
- package/expertise/performance/mobile/mobile-startup-time.md +505 -0
- package/expertise/performance/platform-specific/flutter-performance.md +647 -0
- package/expertise/performance/platform-specific/index.md +22 -0
- package/expertise/performance/platform-specific/node-performance.md +1307 -0
- package/expertise/performance/platform-specific/postgres-performance.md +1366 -0
- package/expertise/performance/platform-specific/react-performance.md +1403 -0
- package/expertise/performance/web/bundle-optimization.md +1239 -0
- package/expertise/performance/web/image-and-media.md +636 -0
- package/expertise/performance/web/index.md +24 -0
- package/expertise/performance/web/network-optimization.md +1133 -0
- package/expertise/performance/web/rendering-performance.md +1098 -0
- package/expertise/performance/web/ssr-and-hydration.md +918 -0
- package/expertise/performance/web/web-vitals.md +1374 -0
- package/expertise/quality/accessibility.md +985 -0
- package/expertise/quality/evidence-based-verification.md +499 -0
- package/expertise/quality/index.md +24 -0
- package/expertise/quality/ml-model-audit.md +614 -0
- package/expertise/quality/performance.md +600 -0
- package/expertise/quality/testing-api.md +891 -0
- package/expertise/quality/testing-mobile.md +496 -0
- package/expertise/quality/testing-web.md +849 -0
- package/expertise/security/PROGRESS.md +54 -0
- package/expertise/security/agentic-identity.md +540 -0
- package/expertise/security/compliance-frameworks.md +601 -0
- package/expertise/security/data/data-encryption.md +364 -0
- package/expertise/security/data/data-privacy-gdpr.md +692 -0
- package/expertise/security/data/database-security.md +1171 -0
- package/expertise/security/data/index.md +22 -0
- package/expertise/security/data/pii-handling.md +531 -0
- package/expertise/security/foundations/authentication.md +1041 -0
- package/expertise/security/foundations/authorization.md +603 -0
- package/expertise/security/foundations/cryptography.md +1001 -0
- package/expertise/security/foundations/index.md +25 -0
- package/expertise/security/foundations/owasp-top-10.md +1354 -0
- package/expertise/security/foundations/secrets-management.md +1217 -0
- package/expertise/security/foundations/secure-sdlc.md +700 -0
- package/expertise/security/foundations/supply-chain-security.md +698 -0
- package/expertise/security/index.md +31 -0
- package/expertise/security/infrastructure/cloud-security-aws.md +1296 -0
- package/expertise/security/infrastructure/cloud-security-gcp.md +1376 -0
- package/expertise/security/infrastructure/container-security.md +721 -0
- package/expertise/security/infrastructure/incident-response.md +1295 -0
- package/expertise/security/infrastructure/index.md +24 -0
- package/expertise/security/infrastructure/logging-and-monitoring.md +1618 -0
- package/expertise/security/infrastructure/network-security.md +1337 -0
- package/expertise/security/mobile/index.md +23 -0
- package/expertise/security/mobile/mobile-android-security.md +1218 -0
- package/expertise/security/mobile/mobile-binary-protection.md +1229 -0
- package/expertise/security/mobile/mobile-data-storage.md +1265 -0
- package/expertise/security/mobile/mobile-ios-security.md +1401 -0
- package/expertise/security/mobile/mobile-network-security.md +1520 -0
- package/expertise/security/smart-contract-security.md +594 -0
- package/expertise/security/testing/index.md +22 -0
- package/expertise/security/testing/penetration-testing.md +1258 -0
- package/expertise/security/testing/security-code-review.md +1765 -0
- package/expertise/security/testing/threat-modeling.md +1074 -0
- package/expertise/security/testing/vulnerability-scanning.md +1062 -0
- package/expertise/security/web/api-security.md +586 -0
- package/expertise/security/web/cors-and-headers.md +433 -0
- package/expertise/security/web/csrf.md +562 -0
- package/expertise/security/web/file-upload.md +1477 -0
- package/expertise/security/web/index.md +25 -0
- package/expertise/security/web/injection.md +1375 -0
- package/expertise/security/web/session-management.md +1101 -0
- package/expertise/security/web/xss.md +1158 -0
- package/exports/README.md +17 -0
- package/exports/hosts/claude/.claude/agents/clarifier.md +42 -0
- package/exports/hosts/claude/.claude/agents/content-author.md +63 -0
- package/exports/hosts/claude/.claude/agents/designer.md +55 -0
- package/exports/hosts/claude/.claude/agents/executor.md +55 -0
- package/exports/hosts/claude/.claude/agents/learner.md +51 -0
- package/exports/hosts/claude/.claude/agents/planner.md +53 -0
- package/exports/hosts/claude/.claude/agents/researcher.md +43 -0
- package/exports/hosts/claude/.claude/agents/reviewer.md +54 -0
- package/exports/hosts/claude/.claude/agents/specifier.md +47 -0
- package/exports/hosts/claude/.claude/agents/verifier.md +71 -0
- package/exports/hosts/claude/.claude/commands/author.md +42 -0
- package/exports/hosts/claude/.claude/commands/clarify.md +38 -0
- package/exports/hosts/claude/.claude/commands/design-review.md +46 -0
- package/exports/hosts/claude/.claude/commands/design.md +44 -0
- package/exports/hosts/claude/.claude/commands/discover.md +37 -0
- package/exports/hosts/claude/.claude/commands/execute.md +48 -0
- package/exports/hosts/claude/.claude/commands/learn.md +38 -0
- package/exports/hosts/claude/.claude/commands/plan-review.md +42 -0
- package/exports/hosts/claude/.claude/commands/plan.md +39 -0
- package/exports/hosts/claude/.claude/commands/prepare-next.md +37 -0
- package/exports/hosts/claude/.claude/commands/review.md +40 -0
- package/exports/hosts/claude/.claude/commands/run-audit.md +41 -0
- package/exports/hosts/claude/.claude/commands/spec-challenge.md +41 -0
- package/exports/hosts/claude/.claude/commands/specify.md +38 -0
- package/exports/hosts/claude/.claude/commands/verify.md +37 -0
- package/exports/hosts/claude/.claude/settings.json +34 -0
- package/exports/hosts/claude/CLAUDE.md +19 -0
- package/exports/hosts/claude/export.manifest.json +38 -0
- package/exports/hosts/claude/host-package.json +67 -0
- package/exports/hosts/codex/AGENTS.md +19 -0
- package/exports/hosts/codex/export.manifest.json +38 -0
- package/exports/hosts/codex/host-package.json +41 -0
- package/exports/hosts/cursor/.cursor/hooks.json +16 -0
- package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +19 -0
- package/exports/hosts/cursor/export.manifest.json +38 -0
- package/exports/hosts/cursor/host-package.json +42 -0
- package/exports/hosts/gemini/GEMINI.md +19 -0
- package/exports/hosts/gemini/export.manifest.json +38 -0
- package/exports/hosts/gemini/host-package.json +41 -0
- package/hooks/README.md +18 -0
- package/hooks/definitions/loop_cap_guard.yaml +21 -0
- package/hooks/definitions/post_tool_capture.yaml +24 -0
- package/hooks/definitions/pre_compact_summary.yaml +19 -0
- package/hooks/definitions/pre_tool_capture_route.yaml +19 -0
- package/hooks/definitions/protected_path_write_guard.yaml +19 -0
- package/hooks/definitions/session_start.yaml +19 -0
- package/hooks/definitions/stop_handoff_harvest.yaml +20 -0
- package/hooks/loop-cap-guard +17 -0
- package/hooks/post-tool-lint +36 -0
- package/hooks/protected-path-write-guard +17 -0
- package/hooks/session-start +41 -0
- package/llms-full.txt +2355 -0
- package/llms.txt +43 -0
- package/package.json +79 -0
- package/roles/README.md +20 -0
- package/roles/clarifier.md +42 -0
- package/roles/content-author.md +63 -0
- package/roles/designer.md +55 -0
- package/roles/executor.md +55 -0
- package/roles/learner.md +51 -0
- package/roles/planner.md +53 -0
- package/roles/researcher.md +43 -0
- package/roles/reviewer.md +54 -0
- package/roles/specifier.md +47 -0
- package/roles/verifier.md +71 -0
- package/schemas/README.md +24 -0
- package/schemas/accepted-learning.schema.json +20 -0
- package/schemas/author-artifact.schema.json +156 -0
- package/schemas/clarification.schema.json +19 -0
- package/schemas/design-artifact.schema.json +80 -0
- package/schemas/docs-claim.schema.json +18 -0
- package/schemas/export-manifest.schema.json +20 -0
- package/schemas/hook.schema.json +67 -0
- package/schemas/host-export-package.schema.json +18 -0
- package/schemas/implementation-plan.schema.json +19 -0
- package/schemas/proposed-learning.schema.json +19 -0
- package/schemas/research.schema.json +18 -0
- package/schemas/review.schema.json +29 -0
- package/schemas/run-manifest.schema.json +18 -0
- package/schemas/spec-challenge.schema.json +18 -0
- package/schemas/spec.schema.json +20 -0
- package/schemas/usage.schema.json +102 -0
- package/schemas/verification-proof.schema.json +29 -0
- package/schemas/wazir-manifest.schema.json +173 -0
- package/skills/README.md +40 -0
- package/skills/brainstorming/SKILL.md +77 -0
- package/skills/debugging/SKILL.md +50 -0
- package/skills/design/SKILL.md +61 -0
- package/skills/dispatching-parallel-agents/SKILL.md +128 -0
- package/skills/executing-plans/SKILL.md +70 -0
- package/skills/finishing-a-development-branch/SKILL.md +169 -0
- package/skills/humanize/SKILL.md +123 -0
- package/skills/init-pipeline/SKILL.md +124 -0
- package/skills/prepare-next/SKILL.md +20 -0
- package/skills/receiving-code-review/SKILL.md +123 -0
- package/skills/requesting-code-review/SKILL.md +105 -0
- package/skills/requesting-code-review/code-reviewer.md +108 -0
- package/skills/run-audit/SKILL.md +197 -0
- package/skills/scan-project/SKILL.md +41 -0
- package/skills/self-audit/SKILL.md +153 -0
- package/skills/subagent-driven-development/SKILL.md +154 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
- package/skills/subagent-driven-development/implementer-prompt.md +102 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/skills/tdd/SKILL.md +23 -0
- package/skills/using-git-worktrees/SKILL.md +163 -0
- package/skills/using-skills/SKILL.md +95 -0
- package/skills/verification/SKILL.md +22 -0
- package/skills/wazir/SKILL.md +463 -0
- package/skills/writing-plans/SKILL.md +30 -0
- package/skills/writing-skills/SKILL.md +157 -0
- package/skills/writing-skills/anthropic-best-practices.md +122 -0
- package/skills/writing-skills/persuasion-principles.md +50 -0
- package/templates/README.md +20 -0
- package/templates/artifacts/README.md +10 -0
- package/templates/artifacts/accepted-learning.md +19 -0
- package/templates/artifacts/accepted-learning.template.json +12 -0
- package/templates/artifacts/author.md +74 -0
- package/templates/artifacts/author.template.json +19 -0
- package/templates/artifacts/clarification.md +21 -0
- package/templates/artifacts/clarification.template.json +12 -0
- package/templates/artifacts/execute-notes.md +19 -0
- package/templates/artifacts/implementation-plan.md +21 -0
- package/templates/artifacts/implementation-plan.template.json +11 -0
- package/templates/artifacts/learning-proposal.md +19 -0
- package/templates/artifacts/next-run-handoff.md +21 -0
- package/templates/artifacts/plan-review.md +19 -0
- package/templates/artifacts/proposed-learning.template.json +12 -0
- package/templates/artifacts/research.md +21 -0
- package/templates/artifacts/research.template.json +12 -0
- package/templates/artifacts/review-findings.md +19 -0
- package/templates/artifacts/review.template.json +11 -0
- package/templates/artifacts/run-manifest.template.json +8 -0
- package/templates/artifacts/spec-challenge.md +19 -0
- package/templates/artifacts/spec-challenge.template.json +11 -0
- package/templates/artifacts/spec.md +21 -0
- package/templates/artifacts/spec.template.json +12 -0
- package/templates/artifacts/verification-proof.md +19 -0
- package/templates/artifacts/verification-proof.template.json +11 -0
- package/templates/examples/accepted-learning.example.json +14 -0
- package/templates/examples/author.example.json +152 -0
- package/templates/examples/clarification.example.json +15 -0
- package/templates/examples/docs-claim.example.json +8 -0
- package/templates/examples/export-manifest.example.json +7 -0
- package/templates/examples/host-export-package.example.json +11 -0
- package/templates/examples/implementation-plan.example.json +17 -0
- package/templates/examples/proposed-learning.example.json +13 -0
- package/templates/examples/research.example.json +15 -0
- package/templates/examples/research.example.md +6 -0
- package/templates/examples/review.example.json +17 -0
- package/templates/examples/run-manifest.example.json +9 -0
- package/templates/examples/spec-challenge.example.json +14 -0
- package/templates/examples/spec.example.json +21 -0
- package/templates/examples/verification-proof.example.json +21 -0
- package/templates/examples/wazir-manifest.example.yaml +65 -0
- package/templates/task-definition-schema.md +99 -0
- package/tooling/README.md +20 -0
- package/tooling/src/adapters/context-mode.js +50 -0
- package/tooling/src/capture/command.js +376 -0
- package/tooling/src/capture/store.js +99 -0
- package/tooling/src/capture/usage.js +270 -0
- package/tooling/src/checks/branches.js +50 -0
- package/tooling/src/checks/brand-truth.js +110 -0
- package/tooling/src/checks/changelog.js +231 -0
- package/tooling/src/checks/command-registry.js +36 -0
- package/tooling/src/checks/commits.js +102 -0
- package/tooling/src/checks/docs-drift.js +103 -0
- package/tooling/src/checks/docs-truth.js +201 -0
- package/tooling/src/checks/runtime-surface.js +156 -0
- package/tooling/src/cli.js +116 -0
- package/tooling/src/command-options.js +56 -0
- package/tooling/src/commands/validate.js +320 -0
- package/tooling/src/doctor/command.js +91 -0
- package/tooling/src/export/command.js +77 -0
- package/tooling/src/export/compiler.js +498 -0
- package/tooling/src/guards/loop-cap-guard.js +52 -0
- package/tooling/src/guards/protected-path-write-guard.js +67 -0
- package/tooling/src/index/command.js +152 -0
- package/tooling/src/index/storage.js +1061 -0
- package/tooling/src/index/summarizers.js +261 -0
- package/tooling/src/loaders.js +18 -0
- package/tooling/src/project-root.js +22 -0
- package/tooling/src/recall/command.js +225 -0
- package/tooling/src/schema-validator.js +30 -0
- package/tooling/src/state-root.js +40 -0
- package/tooling/src/status/command.js +71 -0
- package/wazir.manifest.yaml +135 -0
- package/workflows/README.md +19 -0
- package/workflows/author.md +42 -0
- package/workflows/clarify.md +38 -0
- package/workflows/design-review.md +46 -0
- package/workflows/design.md +44 -0
- package/workflows/discover.md +37 -0
- package/workflows/execute.md +48 -0
- package/workflows/learn.md +38 -0
- package/workflows/plan-review.md +42 -0
- package/workflows/plan.md +39 -0
- package/workflows/prepare-next.md +37 -0
- package/workflows/review.md +40 -0
- package/workflows/run-audit.md +41 -0
- package/workflows/spec-challenge.md +41 -0
- package/workflows/specify.md +38 -0
- package/workflows/verify.md +37 -0
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
# Flutter Performance — Performance Expertise Module
|
|
2
|
+
|
|
3
|
+
> Flutter renders at 60/120fps using its own rendering engine (Impeller/Skia). Performance issues manifest as dropped frames (jank), excessive memory usage, slow startup, and shader compilation stutters. Understanding Flutter's rendering pipeline — build, layout, paint, composite — is key to building smooth apps.
|
|
4
|
+
|
|
5
|
+
> **Impact:** Critical
|
|
6
|
+
> **Applies to:** Mobile (iOS, Android), Web, Desktop
|
|
7
|
+
> **Key metrics:** Frame render time (<16ms for 60fps, <8.3ms for 120fps), Startup time, Memory usage, Shader compilation time
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why This Matters
|
|
12
|
+
|
|
13
|
+
Flutter owns the entire rendering pipeline — every pixel is drawn by its engine, not platform widgets. Performance mistakes translate directly to visible jank.
|
|
14
|
+
|
|
15
|
+
- At 60fps each frame must complete in **16.67ms**; at 120fps the budget is **8.33ms**.
|
|
16
|
+
- Users perceive jank at as few as 3-5 dropped frames in sequence.
|
|
17
|
+
- Shader compilation on first run can spike frame time from 16ms to **90-300ms**, dropping FPS to 6.
|
|
18
|
+
- Cold startup >4s correlates with 25% higher abandonment on mobile.
|
|
19
|
+
- A production e-commerce app cut frame drops from 12% (Skia) to 1.5% (Impeller).
|
|
20
|
+
- One startup reduced app size from 45MB to 32MB and startup from 2.5s to 1.3s via tree-shaking.
|
|
21
|
+
|
|
22
|
+
Flutter's four rendering phases each have distinct performance characteristics:
|
|
23
|
+
1. **Build** — constructs widget tree (Dart, UI thread)
|
|
24
|
+
2. **Layout** — calculates sizes and positions (RenderObject tree)
|
|
25
|
+
3. **Paint** — records drawing commands (Layer tree)
|
|
26
|
+
4. **Composite** — sends layers to GPU (Raster thread)
|
|
27
|
+
|
|
28
|
+
Profiling must distinguish build-phase bottlenecks (CPU, UI thread) from paint/raster bottlenecks (GPU, raster thread).
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Performance Budgets & Targets
|
|
33
|
+
|
|
34
|
+
| Display Rate | Frame Budget | Build Target | Paint Target |
|
|
35
|
+
|-------------|-------------|-------------|-------------|
|
|
36
|
+
| 60 Hz | 16.67ms | <8ms | <8ms |
|
|
37
|
+
| 90 Hz | 11.11ms | <6ms | <5ms |
|
|
38
|
+
| 120 Hz | 8.33ms | <4ms | <4ms |
|
|
39
|
+
|
|
40
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
41
|
+
|--------|------|------------|------------|
|
|
42
|
+
| Cold start (release) | <2s | 2-4s | >4s |
|
|
43
|
+
| Warm start | <1s | 1-2s | >2s |
|
|
44
|
+
| Memory (typical) | <150MB | 150-300MB | >300MB |
|
|
45
|
+
| Memory (low-end 2GB) | <80MB | 80-120MB | >120MB |
|
|
46
|
+
| App size Android APK | <20MB | 20-40MB | >40MB |
|
|
47
|
+
| App size iOS IPA | <30MB | 30-60MB | >60MB |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Measurement & Profiling
|
|
52
|
+
|
|
53
|
+
**Golden rule:** Always profile in **profile mode** (`flutter run --profile`). Debug mode includes assertions and disables AOT — its numbers are meaningless.
|
|
54
|
+
|
|
55
|
+
**Performance Overlay** — fastest check. Two graphs: UI thread (top) and Raster thread (bottom). Green = within budget, Red = over budget.
|
|
56
|
+
```dart
|
|
57
|
+
MaterialApp(showPerformanceOverlay: true);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**DevTools Timeline** — frame-by-frame build/layout/paint durations. Enable "Track Widget Builds" for widget-level granularity. Flame chart shows exact rebuild hierarchy.
|
|
61
|
+
|
|
62
|
+
**CPU Profiler** — bottom-up view finds hottest functions; call-tree view traces the call hierarchy.
|
|
63
|
+
|
|
64
|
+
**Memory View** — heap snapshots, allocation tracking, GC timeline. Diff two snapshots to find leaks (objects persisting when they should not).
|
|
65
|
+
|
|
66
|
+
**Programmatic tracing:**
|
|
67
|
+
```dart
|
|
68
|
+
import 'dart:developer';
|
|
69
|
+
Timeline.startSync('ExpensiveOp');
|
|
70
|
+
// ... work ...
|
|
71
|
+
Timeline.finishSync();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Integration test profiling** produces `timeline_summary.json` with `average_frame_build_time_millis`, `worst_frame_build_time_millis`, `missed_frame_build_budget_count`:
|
|
75
|
+
```bash
|
|
76
|
+
flutter test integration_test/perf_test.dart --profile
|
|
77
|
+
```
|
|
78
|
+
Gate CI on `average_frame_build_time_millis < 16`.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Common Bottlenecks
|
|
83
|
+
|
|
84
|
+
### 1. Missing const Constructors
|
|
85
|
+
Without `const`, every child is reconstructed on parent rebuild even if unchanged. Adding const where applicable reduces rebuild work by **40-60%** in a typical 50-widget screen.
|
|
86
|
+
|
|
87
|
+
### 2. setState at Too High a Level
|
|
88
|
+
Calling `setState()` on a Scaffold-level widget rebuilds hundreds of descendants. Push state to the smallest widget that needs it. Reducing scope from full-screen to single counter: **12ms to <1ms** rebuild.
|
|
89
|
+
|
|
90
|
+
### 3. Expensive build() Methods
|
|
91
|
+
Computation, sorting, filtering inside `build()` is amplified 60x/second during animations. Move to `initState()` or state management layer.
|
|
92
|
+
|
|
93
|
+
### 4. ListView Instead of ListView.builder
|
|
94
|
+
Default `ListView` instantiates all children eagerly. 10,000 items: **~2,000ms** initial build. `ListView.builder`: **~16ms** (only visible items constructed).
|
|
95
|
+
|
|
96
|
+
### 5. Shader Compilation Jank
|
|
97
|
+
First-use shader compilation costs **90-300ms** on older devices. SkSL warmup reduced worst-frame on Moto G4 from ~90ms to ~40ms, iPhone 4s from ~300ms to ~80ms. **Impeller** (default since Flutter 3.22+) eliminates this entirely by pre-compiling all shaders at build time.
|
|
98
|
+
|
|
99
|
+
### 6. Large Unresized Images
|
|
100
|
+
A 4000x3000 image decoded at full resolution uses **~48MB**. At display size (400x300) it uses **~480KB** — 100x reduction. Use `cacheWidth`/`cacheHeight`.
|
|
101
|
+
|
|
102
|
+
### 7. Blocking Main Isolate
|
|
103
|
+
JSON parsing of 2MB response takes ~50-200ms synchronously. On background isolate: zero frame drops.
|
|
104
|
+
|
|
105
|
+
### 8. Platform Channel Overhead
|
|
106
|
+
Each MethodChannel call has ~0.01-0.1ms serialization overhead. Fine for <10 calls/second; for >100/second use Dart FFI (~0.001ms per call).
|
|
107
|
+
|
|
108
|
+
### 9. FutureBuilder Without Cached Future
|
|
109
|
+
Creating a Future inside `build()` restarts the async operation on every rebuild — observed 4x duplicate API calls per screen. Store the Future in `initState()`.
|
|
110
|
+
|
|
111
|
+
### 10. Unoptimized Animations
|
|
112
|
+
Using `setState()` in animation ticks rebuilds entire subtrees 60x/second. Use `AnimatedBuilder` with `child` parameter.
|
|
113
|
+
|
|
114
|
+
### 11. Excessive Widget Nesting
|
|
115
|
+
Trees >30 levels deep increase traversal cost for build, layout, and hit-testing. Flatten with `Container` (combines padding/decoration/alignment).
|
|
116
|
+
|
|
117
|
+
### 12. Undisposed Controllers
|
|
118
|
+
AnimationControllers, StreamSubscriptions, Timers not disposed in `dispose()` leak memory and consume CPU after widget removal.
|
|
119
|
+
|
|
120
|
+
### 13. Helper Methods Instead of Widget Extraction
|
|
121
|
+
Helper methods (`Widget _buildHeader()`) cannot use `const`, always rebuild with parent, and prevent framework optimizations. Extract to separate widget classes.
|
|
122
|
+
|
|
123
|
+
### 14. Opacity Widget for Hiding
|
|
124
|
+
`Opacity` forces painting into an intermediate buffer even at 0.0. Use `Visibility` or conditionally remove from tree.
|
|
125
|
+
|
|
126
|
+
### 15. Monolithic State Subscriptions
|
|
127
|
+
Single giant Provider where every widget listens to entire state. A change to any field rebuilds all listeners. Split into granular providers; use `select()`.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Optimization Patterns
|
|
132
|
+
|
|
133
|
+
### 1. const Constructors
|
|
134
|
+
```dart
|
|
135
|
+
// BEFORE: Rebuilt every parent rebuild
|
|
136
|
+
Icon(Icons.star, color: Colors.yellow, size: 24),
|
|
137
|
+
// AFTER: Instantiated once, reused
|
|
138
|
+
const Icon(Icons.star, color: Colors.yellow, size: 24),
|
|
139
|
+
```
|
|
140
|
+
**Impact:** 50-widget screen rebuild: **8ms to 3ms** (62% reduction). Zero downside. Enable `prefer_const_constructors` lint.
|
|
141
|
+
|
|
142
|
+
### 2. Widget Extraction over Method Extraction
|
|
143
|
+
```dart
|
|
144
|
+
// ANTI-PATTERN: Helper method — rebuilds with parent
|
|
145
|
+
Widget _buildHeader() => Container(child: const Text('Header'));
|
|
146
|
+
|
|
147
|
+
// PATTERN: Extracted widget — const, independent rebuild cycle
|
|
148
|
+
class _Header extends StatelessWidget {
|
|
149
|
+
const _Header();
|
|
150
|
+
@override
|
|
151
|
+
Widget build(BuildContext context) => Container(child: const Text('Header'));
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
**Impact:** 5 extracted sections: rebuild **6ms to 2ms**. Trade-off: more boilerplate per widget.
|
|
155
|
+
|
|
156
|
+
### 3. Isolate.run for Compute
|
|
157
|
+
```dart
|
|
158
|
+
// BEFORE: Blocks UI thread
|
|
159
|
+
final data = jsonDecode(response.body); // ~120ms, 7+ dropped frames
|
|
160
|
+
|
|
161
|
+
// AFTER: Background isolate
|
|
162
|
+
final data = await Isolate.run(() => jsonDecode(response.body)); // 0 dropped frames
|
|
163
|
+
```
|
|
164
|
+
**Threshold rule:** offload if task takes >16ms. Spawn overhead is ~5-20ms. For repeated tasks, use long-lived isolates.
|
|
165
|
+
|
|
166
|
+
### 4. ListView.builder with itemExtent
|
|
167
|
+
```dart
|
|
168
|
+
ListView.builder(
|
|
169
|
+
itemCount: items.length,
|
|
170
|
+
itemExtent: 72.0, // Skips per-item layout measurement
|
|
171
|
+
itemBuilder: (context, index) => ListTile(title: Text(items[index].name)),
|
|
172
|
+
);
|
|
173
|
+
```
|
|
174
|
+
**Impact:** Reduces scroll jank by skipping layout calculation. Trade-off: requires uniform item height. Use `prototypeItem` for measured-once approach.
|
|
175
|
+
|
|
176
|
+
### 5. RepaintBoundary Placement
|
|
177
|
+
```dart
|
|
178
|
+
Column(children: [
|
|
179
|
+
const Header(),
|
|
180
|
+
RepaintBoundary(child: LiveChart()), // Repaints at 60fps without affecting Header
|
|
181
|
+
const Footer(),
|
|
182
|
+
]);
|
|
183
|
+
```
|
|
184
|
+
**Impact:** Paint time **8ms to 2ms** for surrounding static widgets. Trade-off: each boundary allocates ~50-200KB GPU memory. Profile first; only use where paint frequency genuinely differs.
|
|
185
|
+
|
|
186
|
+
### 6. Image Optimization
|
|
187
|
+
```dart
|
|
188
|
+
CachedNetworkImage(
|
|
189
|
+
imageUrl: url,
|
|
190
|
+
memCacheWidth: 400, memCacheHeight: 300, // Decode at display size
|
|
191
|
+
);
|
|
192
|
+
```
|
|
193
|
+
**Impact:** 20-image grid memory: **960MB to 9.6MB** (100x reduction). No OOM crashes on 2GB devices.
|
|
194
|
+
|
|
195
|
+
### 7. AnimatedBuilder with child
|
|
196
|
+
```dart
|
|
197
|
+
AnimatedBuilder(
|
|
198
|
+
animation: _controller,
|
|
199
|
+
child: const Column(children: [Icon(Icons.refresh), Text('Loading')]), // Built once
|
|
200
|
+
builder: (context, child) => Transform.rotate(
|
|
201
|
+
angle: _controller.value * 2 * pi, child: child, // Reused each frame
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
```
|
|
205
|
+
**Impact:** Per-frame build: **4ms to 0.3ms**. Over 1-second animation: **222ms saved**.
|
|
206
|
+
|
|
207
|
+
### 8. Shader Warmup / Impeller
|
|
208
|
+
```bash
|
|
209
|
+
# Legacy (Skia): capture and bundle shaders
|
|
210
|
+
flutter run --profile --cache-sksl # Press M to save
|
|
211
|
+
flutter build apk --bundle-sksl-path=flutter_01.sksl.json
|
|
212
|
+
|
|
213
|
+
# Modern: Impeller (default Flutter 3.22+) — no warmup needed
|
|
214
|
+
flutter run --enable-impeller # Explicit opt-in on older versions
|
|
215
|
+
```
|
|
216
|
+
**Impact:** Impeller: 50% faster rasterization, consistent 120fps, frame drops 12% to 1.5%.
|
|
217
|
+
|
|
218
|
+
### 9. Selective State Rebuilds
|
|
219
|
+
```dart
|
|
220
|
+
// BEFORE: All 3 widgets rebuild when any field changes
|
|
221
|
+
Consumer<AppState>(builder: (_, state, __) => Column(children: [
|
|
222
|
+
Text('${state.count}'), Text(state.name), UserAvatar(url: state.avatar),
|
|
223
|
+
]));
|
|
224
|
+
|
|
225
|
+
// AFTER (Riverpod): Each rebuilds only when its data changes
|
|
226
|
+
Text('${ref.watch(appStateProvider.select((s) => s.count))}'),
|
|
227
|
+
```
|
|
228
|
+
**Impact:** Dashboard with 20 fields: **10-20x rebuild reduction** with selectors.
|
|
229
|
+
|
|
230
|
+
### 10. Deferred Loading
|
|
231
|
+
```dart
|
|
232
|
+
import 'package:my_app/analytics.dart' deferred as analytics;
|
|
233
|
+
Future<void> openAnalytics() async {
|
|
234
|
+
await analytics.loadLibrary(); // ~100-500ms first access
|
|
235
|
+
navigator.push(MaterialPageRoute(builder: (_) => analytics.AnalyticsPage()));
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
**Impact:** Web initial bundle 3.2MB to 1.1MB. Cold startup decreased ~40%.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Anti-Patterns
|
|
243
|
+
|
|
244
|
+
| Anti-Pattern | Why Wrong | Fix |
|
|
245
|
+
|-------------|-----------|-----|
|
|
246
|
+
| `Opacity(opacity: 0)` to hide | Forces intermediate buffer paint; child still in layout/hit-test | `Visibility` or conditional removal |
|
|
247
|
+
| Future created in `build()` for FutureBuilder | Restarts async op every rebuild; 4x duplicate API calls | Create Future in `initState()`, store as field |
|
|
248
|
+
| Helper methods instead of widgets | Cannot use const; always rebuild with parent | Extract to `StatelessWidget` classes |
|
|
249
|
+
| AnimatedBuilder without `child` | Entire subtree rebuilt 60x/second | Pass static subtree as `child` parameter |
|
|
250
|
+
| Missing Keys in dynamic lists | State jumps between items on reorder; forced full rebuilds | `ValueKey(item.id)` with stable identifier |
|
|
251
|
+
| Monolithic global state | Every change rebuilds every listener | Split providers; use `select()` |
|
|
252
|
+
| Excessive RepaintBoundary | Each allocates GPU layer (~50-200KB); overhead if parent/child always repaint together | Profile first; verify improvement in DevTools |
|
|
253
|
+
| Undisposed controllers | Memory leaks, phantom state updates, CPU waste | Call `.dispose()` / `.cancel()` in `dispose()` |
|
|
254
|
+
| Sync I/O in `build()` | Blocks UI thread; even 5ms pushes frame over budget | Load async in `initState()`, cache results |
|
|
255
|
+
| `setState()` as blunt-force rebuild | Rebuilds entire subtree when only small part changed | Push state down; use ValueListenableBuilder |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Architecture-Level Decisions
|
|
260
|
+
|
|
261
|
+
### State Management Performance
|
|
262
|
+
|
|
263
|
+
| Solution | Rebuild Granularity | Overhead | Best For |
|
|
264
|
+
|----------|-------------------|----------|----------|
|
|
265
|
+
| Provider | Medium (manual Selector) | Low | Simple apps |
|
|
266
|
+
| Riverpod | High (compile-safe, lazy, auto-dispose) | Low | Most apps (best default) |
|
|
267
|
+
| Bloc | High (buildWhen, BlocSelector) | Medium (streams) | Complex, strict architecture |
|
|
268
|
+
| GetX | Low (hard to scope) | Low | Prototypes only |
|
|
269
|
+
|
|
270
|
+
Riverpod and Bloc both achieve fine-grained rebuilds. Riverpod has lower overhead (lazy evaluation). Bloc has more predictable state transitions but more stream management overhead.
|
|
271
|
+
|
|
272
|
+
### Platform Channels vs FFI
|
|
273
|
+
|
|
274
|
+
| Approach | Overhead/call | Use when |
|
|
275
|
+
|----------|--------------|----------|
|
|
276
|
+
| MethodChannel/Pigeon | ~0.01-0.1ms | Occasional calls (<10/s) |
|
|
277
|
+
| EventChannel | Same per msg | Continuous streams (sensors) |
|
|
278
|
+
| Dart FFI | ~0.001ms | High-frequency (>100/s), compute-heavy |
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Testing & Regression Prevention
|
|
283
|
+
|
|
284
|
+
### Integration Test Profiling
|
|
285
|
+
```dart
|
|
286
|
+
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
287
|
+
testWidgets('scroll perf', (tester) async {
|
|
288
|
+
await tester.pumpWidget(const MyApp());
|
|
289
|
+
await binding.traceAction(() async {
|
|
290
|
+
await tester.fling(find.byType(ListView), const Offset(0, -3000), 5000);
|
|
291
|
+
await tester.pumpAndSettle();
|
|
292
|
+
}, reportKey: 'scroll_timeline');
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### CI Performance Gates
|
|
297
|
+
```yaml
|
|
298
|
+
# Extract metrics from timeline_summary.json
|
|
299
|
+
- run: |
|
|
300
|
+
AVG=$(jq '.average_frame_build_time_millis' build/timeline_summary.json)
|
|
301
|
+
WORST=$(jq '.worst_frame_build_time_millis' build/timeline_summary.json)
|
|
302
|
+
if (( $(echo "$AVG > 8" | bc -l) )); then echo "FAIL: avg ${AVG}ms > 8ms"; exit 1; fi
|
|
303
|
+
if (( $(echo "$WORST > 32" | bc -l) )); then echo "FAIL: worst ${WORST}ms > 32ms"; exit 1; fi
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Memory Leak Testing
|
|
307
|
+
```dart
|
|
308
|
+
testWidgets('no leaks', experimentalLeakTesting: LeakTesting.settings, (tester) async {
|
|
309
|
+
await tester.pumpWidget(const MaterialApp(home: ProductPage()));
|
|
310
|
+
await tester.pumpWidget(const MaterialApp(home: SizedBox())); // triggers dispose
|
|
311
|
+
// leak_tracker asserts no retained objects
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Decision Trees
|
|
318
|
+
|
|
319
|
+
### "My App is Janky"
|
|
320
|
+
```
|
|
321
|
+
First run only? → Shader jank → Use Impeller (or SkSL warmup for Skia)
|
|
322
|
+
Persistent? → Enable performance overlay →
|
|
323
|
+
Top graph red (UI thread)? → Build/layout issue →
|
|
324
|
+
Many widgets rebuilding? → Add const, extract widgets, scope setState
|
|
325
|
+
build() doing computation? → Move to initState/Isolate
|
|
326
|
+
Layout slow? → Simplify nesting, add itemExtent
|
|
327
|
+
Bottom graph red (Raster thread)? → Paint/GPU issue →
|
|
328
|
+
Using Opacity with fractional values? → Use FadeTransition
|
|
329
|
+
Large images? → Add cacheWidth/cacheHeight
|
|
330
|
+
Complex CustomPaint? → Add RepaintBoundary
|
|
331
|
+
saveLayer calls? → Minimize ClipRRect, BackdropFilter
|
|
332
|
+
Neither red? → Not rendering issue →
|
|
333
|
+
Check main isolate blocking (network, DB, file I/O)
|
|
334
|
+
Check excessive platform channel calls
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### "Should I Use an Isolate?"
|
|
338
|
+
```
|
|
339
|
+
Task duration <1ms? → No, overhead not justified
|
|
340
|
+
1-16ms? → Only if it pushes total frame time over budget
|
|
341
|
+
16-100ms? → Yes, use Isolate.run()
|
|
342
|
+
>100ms? → Yes, Isolate.run() or long-lived isolate
|
|
343
|
+
|
|
344
|
+
Repeated operation? → One-off: Isolate.run(). Frequent (>1/s): long-lived isolate
|
|
345
|
+
Large data transfer? → >1MB: use TransferableTypedData for zero-copy
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Code Examples
|
|
351
|
+
|
|
352
|
+
### 1. setState Scope Reduction
|
|
353
|
+
```dart
|
|
354
|
+
// BEFORE: setState rebuilds entire screen (~12ms build time)
|
|
355
|
+
class ProductScreen extends StatefulWidget {
|
|
356
|
+
@override
|
|
357
|
+
State<ProductScreen> createState() => _ProductScreenState();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
class _ProductScreenState extends State<ProductScreen> {
|
|
361
|
+
int _qty = 1;
|
|
362
|
+
|
|
363
|
+
@override
|
|
364
|
+
Widget build(BuildContext context) {
|
|
365
|
+
return Scaffold(
|
|
366
|
+
body: Column(children: [
|
|
367
|
+
const ProductImage(), // Rebuilt unnecessarily
|
|
368
|
+
const ProductDescription(), // Rebuilt unnecessarily
|
|
369
|
+
Text('Qty: $_qty'),
|
|
370
|
+
ElevatedButton(
|
|
371
|
+
onPressed: () => setState(() => _qty++),
|
|
372
|
+
child: const Text('Add'),
|
|
373
|
+
),
|
|
374
|
+
]),
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// AFTER: Only _QuantitySelector rebuilds (~0.5ms, 96% reduction)
|
|
380
|
+
class ProductScreen extends StatelessWidget {
|
|
381
|
+
const ProductScreen();
|
|
382
|
+
|
|
383
|
+
@override
|
|
384
|
+
Widget build(BuildContext context) {
|
|
385
|
+
return const Scaffold(
|
|
386
|
+
body: Column(children: [
|
|
387
|
+
ProductImage(),
|
|
388
|
+
ProductDescription(),
|
|
389
|
+
_QuantitySelector(), // Isolated state — only this rebuilds
|
|
390
|
+
]),
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
class _QuantitySelector extends StatefulWidget {
|
|
396
|
+
const _QuantitySelector();
|
|
397
|
+
@override
|
|
398
|
+
State<_QuantitySelector> createState() => _QuantitySelectorState();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
class _QuantitySelectorState extends State<_QuantitySelector> {
|
|
402
|
+
int _qty = 1;
|
|
403
|
+
|
|
404
|
+
@override
|
|
405
|
+
Widget build(BuildContext context) {
|
|
406
|
+
return Row(children: [
|
|
407
|
+
Text('Qty: $_qty'),
|
|
408
|
+
ElevatedButton(
|
|
409
|
+
onPressed: () => setState(() => _qty++),
|
|
410
|
+
child: const Text('Add'),
|
|
411
|
+
),
|
|
412
|
+
]);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
**Measured:** Build time per setState: **12ms to 0.5ms** (96% reduction).
|
|
417
|
+
|
|
418
|
+
### 2. Proper FutureBuilder Usage
|
|
419
|
+
```dart
|
|
420
|
+
// BEFORE: Future created in build() — 4x duplicate API calls, flickering UI
|
|
421
|
+
class UserProfile extends StatelessWidget {
|
|
422
|
+
@override
|
|
423
|
+
Widget build(BuildContext context) {
|
|
424
|
+
return FutureBuilder<User>(
|
|
425
|
+
future: fetchUser(), // NEW Future every rebuild — triggers re-fetch
|
|
426
|
+
builder: (context, snapshot) {
|
|
427
|
+
if (!snapshot.hasData) return const CircularProgressIndicator();
|
|
428
|
+
return Text(snapshot.data!.name);
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// AFTER: Future cached in initState — 1 API call, stable UI
|
|
435
|
+
class UserProfile extends StatefulWidget {
|
|
436
|
+
const UserProfile();
|
|
437
|
+
@override
|
|
438
|
+
State<UserProfile> createState() => _UserProfileState();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
class _UserProfileState extends State<UserProfile> {
|
|
442
|
+
late final Future<User> _userFuture;
|
|
443
|
+
|
|
444
|
+
@override
|
|
445
|
+
void initState() {
|
|
446
|
+
super.initState();
|
|
447
|
+
_userFuture = fetchUser(); // Called exactly once
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
@override
|
|
451
|
+
Widget build(BuildContext context) {
|
|
452
|
+
return FutureBuilder<User>(
|
|
453
|
+
future: _userFuture, // Same instance across all rebuilds
|
|
454
|
+
builder: (context, snapshot) {
|
|
455
|
+
if (!snapshot.hasData) return const CircularProgressIndicator();
|
|
456
|
+
return Text(snapshot.data!.name);
|
|
457
|
+
},
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
**Measured:** API calls per screen: **4 to 1** (75% network reduction). Eliminates loading indicator flicker.
|
|
463
|
+
|
|
464
|
+
### 3. ListView.builder with itemExtent
|
|
465
|
+
```dart
|
|
466
|
+
// BEFORE: All 10,000 items built eagerly (~2,000ms initial render)
|
|
467
|
+
ListView(
|
|
468
|
+
children: items.map((item) => ListTile(title: Text(item.name))).toList(),
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
// AFTER: Only visible items built (~16ms initial render)
|
|
472
|
+
ListView.builder(
|
|
473
|
+
itemCount: items.length,
|
|
474
|
+
itemExtent: 72.0, // Known height — framework skips per-item measurement
|
|
475
|
+
itemBuilder: (context, index) {
|
|
476
|
+
return ListTile(
|
|
477
|
+
key: ValueKey(items[index].id), // Stable identity for reorder
|
|
478
|
+
title: Text(items[index].name),
|
|
479
|
+
);
|
|
480
|
+
},
|
|
481
|
+
);
|
|
482
|
+
```
|
|
483
|
+
**Measured:** Initial build: **2,000ms to 16ms**. Scroll jank reduced by removing layout measurement per item.
|
|
484
|
+
|
|
485
|
+
### 4. Image Grid Optimization
|
|
486
|
+
```dart
|
|
487
|
+
// BEFORE: 20 full-resolution images = ~960MB (OOM crash on 2GB devices)
|
|
488
|
+
GridView.builder(
|
|
489
|
+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
|
|
490
|
+
itemCount: images.length,
|
|
491
|
+
itemBuilder: (context, index) => Image.network(images[index].url),
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
// AFTER: Right-sized images with caching = ~9.6MB (100x reduction)
|
|
495
|
+
GridView.builder(
|
|
496
|
+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
|
|
497
|
+
itemCount: images.length,
|
|
498
|
+
itemBuilder: (context, index) => CachedNetworkImage(
|
|
499
|
+
imageUrl: images[index].url,
|
|
500
|
+
memCacheWidth: 200,
|
|
501
|
+
memCacheHeight: 200,
|
|
502
|
+
placeholder: (_, __) => const ColoredBox(color: Colors.grey),
|
|
503
|
+
),
|
|
504
|
+
);
|
|
505
|
+
```
|
|
506
|
+
**Measured:** Memory for 20 images: **960MB to 9.6MB**. No OOM on low-end devices.
|
|
507
|
+
|
|
508
|
+
### 5. Isolate.run for JSON Parsing
|
|
509
|
+
```dart
|
|
510
|
+
// BEFORE: Main isolate blocked (~120ms for 2MB JSON, 7+ dropped frames)
|
|
511
|
+
Future<List<Product>> loadProducts() async {
|
|
512
|
+
final response = await http.get(Uri.parse(apiUrl));
|
|
513
|
+
final List<dynamic> data = jsonDecode(response.body); // Blocks UI thread
|
|
514
|
+
return data.map((e) => Product.fromJson(e)).toList();
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// AFTER: Background isolate — 0 dropped frames
|
|
518
|
+
Future<List<Product>> loadProducts() async {
|
|
519
|
+
final response = await http.get(Uri.parse(apiUrl));
|
|
520
|
+
return Isolate.run(() {
|
|
521
|
+
final List<dynamic> data = jsonDecode(response.body);
|
|
522
|
+
return data.map((e) => Product.fromJson(e)).toList();
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
**Measured:** UI thread block: **120ms to 0ms**. Total time similar but entirely off the UI thread.
|
|
527
|
+
|
|
528
|
+
### 6. AnimatedBuilder with child Parameter
|
|
529
|
+
```dart
|
|
530
|
+
// BEFORE: Static subtree rebuilt 60x/second (~4ms per frame)
|
|
531
|
+
AnimatedBuilder(
|
|
532
|
+
animation: _controller,
|
|
533
|
+
builder: (context, child) {
|
|
534
|
+
return Transform.rotate(
|
|
535
|
+
angle: _controller.value * 2 * pi,
|
|
536
|
+
child: Column(children: [
|
|
537
|
+
const Icon(Icons.refresh, size: 48),
|
|
538
|
+
const Text('Loading...'),
|
|
539
|
+
const SizedBox(height: 16),
|
|
540
|
+
const LinearProgressIndicator(),
|
|
541
|
+
]),
|
|
542
|
+
);
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
// AFTER: Static subtree built once, reused across frames (~0.3ms per frame)
|
|
547
|
+
AnimatedBuilder(
|
|
548
|
+
animation: _controller,
|
|
549
|
+
child: const Column(children: [
|
|
550
|
+
Icon(Icons.refresh, size: 48),
|
|
551
|
+
Text('Loading...'),
|
|
552
|
+
SizedBox(height: 16),
|
|
553
|
+
LinearProgressIndicator(),
|
|
554
|
+
]),
|
|
555
|
+
builder: (context, child) {
|
|
556
|
+
return Transform.rotate(
|
|
557
|
+
angle: _controller.value * 2 * pi,
|
|
558
|
+
child: child, // Reused — not rebuilt
|
|
559
|
+
);
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
```
|
|
563
|
+
**Measured:** Per-frame build: **4ms to 0.3ms**. Over a 1-second 60fps animation: **222ms total savings**.
|
|
564
|
+
|
|
565
|
+
### 7. Proper dispose() for Controllers
|
|
566
|
+
```dart
|
|
567
|
+
class AnimatedCard extends StatefulWidget {
|
|
568
|
+
const AnimatedCard();
|
|
569
|
+
@override
|
|
570
|
+
State<AnimatedCard> createState() => _AnimatedCardState();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
class _AnimatedCardState extends State<AnimatedCard>
|
|
574
|
+
with SingleTickerProviderStateMixin {
|
|
575
|
+
late final AnimationController _controller;
|
|
576
|
+
late final StreamSubscription<Data> _subscription;
|
|
577
|
+
late final ScrollController _scrollController;
|
|
578
|
+
|
|
579
|
+
@override
|
|
580
|
+
void initState() {
|
|
581
|
+
super.initState();
|
|
582
|
+
_controller = AnimationController(vsync: this, duration: const Duration(seconds: 1));
|
|
583
|
+
_scrollController = ScrollController();
|
|
584
|
+
_subscription = dataStream.listen((_) => setState(() {}));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
@override
|
|
588
|
+
void dispose() {
|
|
589
|
+
_controller.dispose(); // Stop ticker, free resources
|
|
590
|
+
_scrollController.dispose(); // Remove scroll listeners
|
|
591
|
+
_subscription.cancel(); // Stop stream listener
|
|
592
|
+
super.dispose();
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
@override
|
|
596
|
+
Widget build(BuildContext context) { /* ... */ }
|
|
597
|
+
}
|
|
598
|
+
```
|
|
599
|
+
**Impact:** Prevents memory leaks, phantom state updates, and ticker-after-dispose crashes. Every controller/subscription/timer must have a matching dispose/cancel.
|
|
600
|
+
|
|
601
|
+
### 8. Shader Warmup and Impeller Migration
|
|
602
|
+
```bash
|
|
603
|
+
# LEGACY (Skia): Capture shaders during manual testing
|
|
604
|
+
flutter run --profile --cache-sksl
|
|
605
|
+
# Exercise all animations, transitions, and complex UI paths
|
|
606
|
+
# Press 'M' in terminal to save captured shaders
|
|
607
|
+
|
|
608
|
+
# Bundle captured shaders into release build
|
|
609
|
+
flutter build apk --bundle-sksl-path=flutter_01.sksl.json
|
|
610
|
+
|
|
611
|
+
# MODERN (Impeller, default Flutter 3.22+): No warmup needed
|
|
612
|
+
# All shaders pre-compiled at engine build time
|
|
613
|
+
# Verify Impeller is active — no --enable-impeller flag needed on latest Flutter
|
|
614
|
+
flutter run --profile
|
|
615
|
+
```
|
|
616
|
+
**Measured (SkSL):** Moto G4 worst-frame: **90ms to 40ms**. iPhone 4s: **300ms to 80ms**.
|
|
617
|
+
**Measured (Impeller):** Frame drops: **12% to 1.5%**. Rasterization **50% faster**. Consistent 120fps.
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
## Quick Reference
|
|
622
|
+
|
|
623
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
624
|
+
|--------|------|------------|------------|
|
|
625
|
+
| Frame build time (60fps) | <8ms | 8-16ms | >16ms |
|
|
626
|
+
| Frame build time (120fps) | <4ms | 4-8ms | >8ms |
|
|
627
|
+
| Frame raster time | <8ms | 8-16ms | >16ms |
|
|
628
|
+
| Cold startup (release) | <2s | 2-4s | >4s |
|
|
629
|
+
| Memory (typical) | <150MB | 150-300MB | >300MB |
|
|
630
|
+
| App size (Android) | <20MB | 20-40MB | >40MB |
|
|
631
|
+
| Missed frames / 1000 | <5 | 5-20 | >20 |
|
|
632
|
+
| Shader compile | 0ms (Impeller) | <40ms (SkSL) | >80ms |
|
|
633
|
+
|
|
634
|
+
### Optimization Priority Order
|
|
635
|
+
1. **Measure first** — profile, do not guess
|
|
636
|
+
2. **Add const constructors** — highest ROI, zero downside
|
|
637
|
+
3. **Scope setState** — push state to smallest widget
|
|
638
|
+
4. **Use ListView.builder** — for lists >20 items
|
|
639
|
+
5. **Cache Futures** — never create in build()
|
|
640
|
+
6. **Offload to Isolates** — for tasks >16ms
|
|
641
|
+
7. **Optimize images** — cacheWidth/cacheHeight
|
|
642
|
+
8. **Use Impeller** — eliminates shader jank
|
|
643
|
+
9. **Extract widgets** — replace helper methods
|
|
644
|
+
10. **RepaintBoundary** — only where profiling confirms paint bottleneck
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
*Researched: 2026-03-08 | Sources: [flutter.dev/perf/best-practices](https://docs.flutter.dev/perf/best-practices), [flutter.dev/perf/impeller](https://docs.flutter.dev/perf/impeller), [flutter.dev/perf/shader](https://docs.flutter.dev/perf/rendering/shader), [flutter.dev/tools/devtools](https://docs.flutter.dev/tools/devtools/performance), [flutter.dev/perf/isolates](https://docs.flutter.dev/perf/isolates), [dart.dev/language/isolates](https://dart.dev/language/isolates), [ITNEXT: 10 Techniques](https://itnext.io/flutter-performance-optimization-10-techniques-that-actually-work-in-2025-4def9e5bbd2d), [DEV: Impeller 2026](https://dev.to/eira-wexford/how-impeller-is-transforming-flutter-ui-rendering-in-2026-3dpd), [DCM: Memory Leaks](https://dcm.dev/blog/2024/10/21/lets-talk-about-memory-leaks-in-dart-and-flutter/), [Flutter API: Opacity](https://api.flutter.dev/flutter/widgets/Opacity-class.html), [Flutter API: RepaintBoundary](https://api.flutter.dev/flutter/widgets/RepaintBoundary-class.html), [iiro.dev: Widget Methods Anti-pattern](https://iirokrankka.com/2018/12/11/splitting-widgets-to-methods-performance-antipattern/), [Digia: Animation Performance](https://www.digia.tech/post/flutter-animation-performance-guide), [Superformula: Optimizing Rebuilds](https://www.superformula.com/articles/optimizing-rebuilds-with-flutter/)*
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Directory Purpose
|
|
2
|
+
|
|
3
|
+
The `platform-specific` performance directory provides deep-dive optimization techniques tailored to specific tools and frameworks.
|
|
4
|
+
|
|
5
|
+
# Key Concepts
|
|
6
|
+
|
|
7
|
+
- Framework-specific rendering cycles
|
|
8
|
+
- Language-level runtime optimizations
|
|
9
|
+
- Database-specific tuning
|
|
10
|
+
|
|
11
|
+
# File Map
|
|
12
|
+
|
|
13
|
+
- `flutter-performance.md` — rebuilds, isolates, and const constructors
|
|
14
|
+
- `node-performance.md` — event loop blocking, clustering, and V8 tuning
|
|
15
|
+
- `postgres-performance.md` — vacuuming, BRIN/GIN indexes, and shared buffers
|
|
16
|
+
- `react-performance.md` — memoization, virtual DOM, and useMemo/useCallback
|
|
17
|
+
|
|
18
|
+
# Reading Guide
|
|
19
|
+
|
|
20
|
+
If optimizing a React app → read `react-performance.md`
|
|
21
|
+
If tuning a Postgres DB → read `postgres-performance.md`
|
|
22
|
+
If debugging a Node service → read `node-performance.md`
|