@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,623 @@
|
|
|
1
|
+
# Premature Optimization Anti-Patterns -- Expertise Module
|
|
2
|
+
|
|
3
|
+
> "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
|
|
4
|
+
> -- Donald Knuth, *Structured Programming with go to Statements* (1974)
|
|
5
|
+
|
|
6
|
+
> Domain: Performance
|
|
7
|
+
> Severity range: Medium to Critical
|
|
8
|
+
> Applies to: All languages, all platforms, all team sizes
|
|
9
|
+
|
|
10
|
+
Premature optimization is the act of making code faster, more memory-efficient, or more scalable before establishing that a measurable problem exists. It trades readability, correctness, and development velocity for speculative performance gains that often fail to materialize -- or worse, introduce bugs and architectural rigidity that cost far more to fix than the original "slow" code ever would. This module catalogs 20 recurring anti-patterns, each documented with real-world consequences, detection heuristics, and corrective guidance.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Anti-Pattern 1: Optimizing Without Profiling
|
|
15
|
+
|
|
16
|
+
**Also known as:** Gut-feel tuning, Optimization by intuition
|
|
17
|
+
|
|
18
|
+
**Description:** Developers modify code to make it "faster" without first measuring where time is actually spent. Human intuition about performance hotspots is notoriously unreliable -- studies consistently show that developers misidentify the bottleneck the majority of the time.
|
|
19
|
+
|
|
20
|
+
**Why it happens:** Performance anxiety during code review; folklore about "slow" constructs inherited from older runtimes; the assumption that local reasoning about a function's cost predicts system-level behavior.
|
|
21
|
+
|
|
22
|
+
**Real-world consequences:** A team at a mid-size SaaS company spent two weeks rewriting their JSON serialization layer in a custom binary format, only to discover through profiling that serialization accounted for 0.3% of total request latency. The actual bottleneck was an unindexed database query consuming 87% of the time. The custom serializer introduced three deserialization bugs that took another week to fix.
|
|
23
|
+
|
|
24
|
+
**The fix:**
|
|
25
|
+
1. Establish a performance baseline with production-representative data.
|
|
26
|
+
2. Profile with an actual profiler (pprof, async-profiler, py-spy, Chrome DevTools, Instruments).
|
|
27
|
+
3. Identify the top 3 hotspots by wall-clock or CPU time.
|
|
28
|
+
4. Optimize only the hotspots, re-measure after each change.
|
|
29
|
+
5. Stop when the target is met.
|
|
30
|
+
|
|
31
|
+
**Detection signals:**
|
|
32
|
+
- Commit messages mention "perf" or "optimize" with no linked benchmark.
|
|
33
|
+
- PR description lacks before/after measurements.
|
|
34
|
+
- Optimization touches code that does not appear in any flame graph.
|
|
35
|
+
|
|
36
|
+
**Severity:** High
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Anti-Pattern 2: Micro-Optimizations That Sacrifice Readability
|
|
41
|
+
|
|
42
|
+
**Also known as:** Clever code syndrome, Micro-optimization theater
|
|
43
|
+
|
|
44
|
+
**Description:** Replacing clear, idiomatic code with obscure constructs for negligible speed gains. Classic examples include using `i >> 1` instead of `i / 2`, replacing `if/else` with ternary chains, or rewriting LINQ/streams as manual loops "for speed."
|
|
45
|
+
|
|
46
|
+
**Why it happens:** Developer ego; competitive coding habits carried into production; misunderstanding of how modern compilers and JIT engines optimize idiomatic code.
|
|
47
|
+
|
|
48
|
+
**Real-world consequences:** Jeff Atwood documented "The Sad Tragedy of Micro-Optimization Theater" where developers spent hours debating whether `StringBuilder` vs string concatenation mattered in a code path executed once per request -- while the page made 47 redundant database calls. The micro-optimization was unmeasurable; the redundant queries added 400ms.
|
|
49
|
+
|
|
50
|
+
**The fix:**
|
|
51
|
+
- Write clear code first. The compiler already optimizes `i / 2` into a shift.
|
|
52
|
+
- Reserve micro-optimization for inner loops that profiling proves are hot.
|
|
53
|
+
- If you must optimize, leave the readable version in a comment.
|
|
54
|
+
|
|
55
|
+
**Detection signals:**
|
|
56
|
+
- Bit shifts used for arithmetic in business logic.
|
|
57
|
+
- Variable names shortened to single characters "to reduce memory."
|
|
58
|
+
- Comments explaining what the code does because the code itself is unreadable.
|
|
59
|
+
|
|
60
|
+
**Severity:** Medium
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Anti-Pattern 3: Caching Everything (Including Cheap Computations)
|
|
65
|
+
|
|
66
|
+
**Also known as:** Cache-itis, Memoize-all
|
|
67
|
+
|
|
68
|
+
**Description:** Wrapping every function result in a cache or memoization layer regardless of computation cost, access frequency, or invalidation complexity. Caching a simple string concatenation or a date format costs more in cache management overhead than recomputing the value.
|
|
69
|
+
|
|
70
|
+
**Why it happens:** "Caching makes things faster" treated as a universal law; unfamiliarity with cache invalidation costs; not measuring the cost of the original computation.
|
|
71
|
+
|
|
72
|
+
**Real-world consequences:** A service aggressively cached API responses to avoid database calls. Early benchmarks showed latency drops. Over time the cache became part of the implicit contract -- every new feature had to handle cache invalidation. Consistency bugs surfaced as stale data served to users. The team spent months adding cache-busting logic that was more complex than the original queries.
|
|
73
|
+
|
|
74
|
+
**The fix:**
|
|
75
|
+
- Only cache results that are expensive to compute AND frequently accessed AND rarely change.
|
|
76
|
+
- Measure the computation cost before adding a cache layer.
|
|
77
|
+
- Always define TTL and invalidation strategy before writing the caching code.
|
|
78
|
+
- Prefer compute-on-demand for operations under 1ms.
|
|
79
|
+
|
|
80
|
+
**Detection signals:**
|
|
81
|
+
- Cache hit ratio below 50% in production metrics.
|
|
82
|
+
- `@Cacheable` or memoize decorators on functions with O(1) complexity.
|
|
83
|
+
- Cache invalidation bugs appearing in the issue tracker.
|
|
84
|
+
- Memory usage growing steadily with no corresponding feature growth.
|
|
85
|
+
|
|
86
|
+
**Severity:** High
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Anti-Pattern 4: Premature Database Denormalization
|
|
91
|
+
|
|
92
|
+
**Also known as:** Flatten-first schema design
|
|
93
|
+
|
|
94
|
+
**Description:** Denormalizing a database schema before any query performance problem has been measured. Developers duplicate columns across tables, embed aggregates, or create materialized views on day one because "JOINs are slow."
|
|
95
|
+
|
|
96
|
+
**Why it happens:** Cargo-culting practices from high-scale companies; reading blog posts about denormalization at Netflix/Facebook scale and applying them to a 10-table app with 500 rows.
|
|
97
|
+
|
|
98
|
+
**Real-world consequences:** A startup denormalized their user-order schema by embedding user profile data in every order row. When users updated their email addresses, 15 different tables needed synchronized updates. A race condition in the sync logic caused orders to be sent to old email addresses for three months before detection. Reverting to a normalized schema required a multi-week migration.
|
|
99
|
+
|
|
100
|
+
**The fix:**
|
|
101
|
+
- Start normalized. A properly indexed normalized schema handles most workloads.
|
|
102
|
+
- Denormalize only after profiling shows JOINs consuming >50% of query time on critical paths.
|
|
103
|
+
- When you denormalize, document which source table is authoritative and build automated consistency checks.
|
|
104
|
+
- Consider materialized views or read replicas before restructuring base tables.
|
|
105
|
+
|
|
106
|
+
**Detection signals:**
|
|
107
|
+
- The same column (e.g., `user_email`) appears in 5+ tables.
|
|
108
|
+
- Update queries touch multiple tables to keep denormalized copies in sync.
|
|
109
|
+
- Data inconsistency bugs in the issue tracker.
|
|
110
|
+
|
|
111
|
+
**Severity:** Critical
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Anti-Pattern 5: Complex Data Structures for Small Datasets
|
|
116
|
+
|
|
117
|
+
**Also known as:** Over-structuring, Algorithmic overkill
|
|
118
|
+
|
|
119
|
+
**Description:** Using B-trees, hash maps, bloom filters, skip lists, or trie structures for datasets with fewer than 100 elements, where a simple array with linear scan would be faster due to CPU cache locality.
|
|
120
|
+
|
|
121
|
+
**Why it happens:** Textbook algorithm analysis focuses on asymptotic complexity, leading developers to choose O(log n) over O(n) without considering that for n=20, the constant factors and cache behavior of a linear scan make it faster than a tree traversal with pointer chasing.
|
|
122
|
+
|
|
123
|
+
**Real-world consequences:** A configuration system used a red-black tree to store application settings (typically 30-50 key-value pairs). The tree implementation had three times the memory overhead of a flat array and was measurably slower for lookups due to poor cache locality. Replacing it with a sorted array and binary search reduced memory usage by 70% and improved lookup time by 40%.
|
|
124
|
+
|
|
125
|
+
**The fix:**
|
|
126
|
+
- For collections under ~100 elements, prefer arrays or flat vectors.
|
|
127
|
+
- Benchmark with realistic dataset sizes, not theoretical worst cases.
|
|
128
|
+
- Remember that L1 cache lines are 64 bytes -- data that fits in cache is fast regardless of algorithmic complexity class.
|
|
129
|
+
|
|
130
|
+
**Detection signals:**
|
|
131
|
+
- `TreeMap` or `HashMap` used for collections that never exceed 50 entries.
|
|
132
|
+
- Custom data structures imported for configuration or lookup tables.
|
|
133
|
+
- Algorithmic complexity cited in comments but dataset size is trivially small.
|
|
134
|
+
|
|
135
|
+
**Severity:** Low to Medium
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Anti-Pattern 6: Hand-Rolling Standard Library Functionality
|
|
140
|
+
|
|
141
|
+
**Also known as:** NIH optimization, Reinventing the wheel for speed
|
|
142
|
+
|
|
143
|
+
**Description:** Writing custom implementations of sorting, hashing, string manipulation, HTTP parsing, or JSON serialization because "the standard library is too general / too slow."
|
|
144
|
+
|
|
145
|
+
**Why it happens:** Distrust of standard library performance without benchmarking; desire for control; belief that a specialized version will be faster. Sometimes valid in embedded or systems programming, but almost never in application code.
|
|
146
|
+
|
|
147
|
+
**Real-world consequences:** A team wrote a custom URL parser "for performance" that was 12% faster than the standard library in microbenchmarks. In production, URL parsing was 0.01% of request time. The custom parser had a bug with percent-encoded Unicode characters that caused a security vulnerability (path traversal) disclosed six months later. The standard library had handled this correctly for years, having been audited by thousands of developers.
|
|
148
|
+
|
|
149
|
+
**The fix:**
|
|
150
|
+
- Use standard library functions by default. They are tested by millions of users and optimized by compiler/runtime engineers.
|
|
151
|
+
- Only replace standard library code when profiling shows it is a genuine bottleneck AND you have comprehensive tests for the replacement.
|
|
152
|
+
- When you do hand-roll, maintain a benchmark suite that compares your implementation against the standard version.
|
|
153
|
+
|
|
154
|
+
**Detection signals:**
|
|
155
|
+
- Custom `sort()`, `hash()`, `parseUrl()`, or `formatDate()` functions in the codebase.
|
|
156
|
+
- Functions that duplicate standard library behavior with slightly different APIs.
|
|
157
|
+
- No benchmark comparing custom vs. standard implementation.
|
|
158
|
+
|
|
159
|
+
**Severity:** High
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Anti-Pattern 7: Optimizing for Rare Edge Cases
|
|
164
|
+
|
|
165
|
+
**Also known as:** Tail-case obsession, 0.01% engineering
|
|
166
|
+
|
|
167
|
+
**Description:** Adding complexity to handle edge cases that occur in less than 1% of executions, at the expense of the common path. Examples include special-casing empty collections, adding fast paths for single-element inputs, or writing SIMD code for a branch that fires once per million requests.
|
|
168
|
+
|
|
169
|
+
**Why it happens:** Completionism; fear of worst-case scenarios; confusing "possible" with "probable."
|
|
170
|
+
|
|
171
|
+
**Real-world consequences:** A payment processing system added a complex batching optimization for processing more than 10,000 transactions simultaneously. The batch path had its own code, its own tests, its own failure modes. In 18 months of production, the batch size never exceeded 200. The batch optimization code was the source of two outages due to untested concurrency bugs, while the normal path ran flawlessly.
|
|
172
|
+
|
|
173
|
+
**The fix:**
|
|
174
|
+
- Measure frequency of each code path before optimizing.
|
|
175
|
+
- Optimize the path that covers 95%+ of executions first.
|
|
176
|
+
- For rare edge cases, correctness and simplicity trump speed.
|
|
177
|
+
- Add monitoring to verify your assumptions about path frequency.
|
|
178
|
+
|
|
179
|
+
**Detection signals:**
|
|
180
|
+
- Complex branching logic with comments like "fast path for edge case X."
|
|
181
|
+
- Specialized code paths with low or zero test coverage.
|
|
182
|
+
- Analytics showing the optimized path is rarely exercised.
|
|
183
|
+
|
|
184
|
+
**Severity:** Medium
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Anti-Pattern 8: Bit Manipulation for "Speed" in Application Code
|
|
189
|
+
|
|
190
|
+
**Also known as:** Bit-twiddling theater
|
|
191
|
+
|
|
192
|
+
**Description:** Using bitwise operations (shifts, masks, XOR tricks) in application-level business logic where arithmetic operators would be clearer and the compiler already generates identical machine code.
|
|
193
|
+
|
|
194
|
+
**Why it happens:** Competitive programming habits; reading "Hacker's Delight" and applying it everywhere; belief that bit operations are inherently faster in all contexts.
|
|
195
|
+
|
|
196
|
+
**Real-world consequences:** The XOR swap trick (`a ^= b; b ^= a; a ^= b;`) is a well-known example: it is less readable than using a temporary variable, and on modern hardware it is actually slower because it introduces data dependencies that prevent instruction-level parallelism. A developer used it in a sorting algorithm's swap function, and a later maintainer misread the XOR chain, introduced a bug where a value was swapped with itself (causing it to become zero), and the bug survived for two releases.
|
|
197
|
+
|
|
198
|
+
**The fix:**
|
|
199
|
+
- Use arithmetic operators for arithmetic. `x / 2` is compiled to a shift by any modern compiler at `-O1` or above.
|
|
200
|
+
- Reserve bit manipulation for genuinely bit-oriented tasks: flags, masks, protocol parsing, graphics.
|
|
201
|
+
- If you use bitwise tricks, always comment the intent and include the readable equivalent.
|
|
202
|
+
|
|
203
|
+
**Detection signals:**
|
|
204
|
+
- `>> 1` used instead of `/ 2` in business logic.
|
|
205
|
+
- XOR swap instead of temp-variable swap.
|
|
206
|
+
- Bitmask arithmetic in code that has nothing to do with hardware or protocols.
|
|
207
|
+
|
|
208
|
+
**Severity:** Medium
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Anti-Pattern 9: Custom Memory Management in Garbage-Collected Languages
|
|
213
|
+
|
|
214
|
+
**Also known as:** Fighting the GC, Manual memory theater
|
|
215
|
+
|
|
216
|
+
**Description:** Implementing object pools, free lists, arena allocators, or explicit `null`-setting in languages like Java, C#, Go, or Python where the garbage collector is designed to handle allocation and reclamation efficiently.
|
|
217
|
+
|
|
218
|
+
**Why it happens:** Experience with C/C++ carried into GC languages; reading GC tuning guides and over-applying the advice; fear of GC pauses without measuring them.
|
|
219
|
+
|
|
220
|
+
**Real-world consequences:** A Java team implemented a custom object pool for request-handling objects to "avoid GC pressure." The pooled objects lived in the old generation, causing longer full GC pauses (not shorter ones) because the collector had to inspect them every cycle. Pooled object reuse also introduced state-leakage bugs where fields from a previous request bled into the next. Removing the pool and letting the GC handle short-lived objects reduced p99 latency by 30%.
|
|
221
|
+
|
|
222
|
+
**The fix:**
|
|
223
|
+
- Trust the GC for short-lived objects. Modern GCs (ZGC, Shenandoah, G1, .NET's workstation GC) are optimized for this pattern.
|
|
224
|
+
- Pool only genuinely expensive-to-create resources: database connections, thread pools, TLS sessions.
|
|
225
|
+
- If GC pauses are a measured problem, tune GC parameters before writing custom allocators.
|
|
226
|
+
- Use `-XX:+UseStringDeduplication` (Java) or similar runtime features before hand-rolling deduplication.
|
|
227
|
+
|
|
228
|
+
**Detection signals:**
|
|
229
|
+
- Object pool classes in a Java/C#/Go codebase for ordinary DTOs or value objects.
|
|
230
|
+
- Explicit `obj = null` lines to "help the GC."
|
|
231
|
+
- `System.gc()` or `GC.Collect()` calls in production code.
|
|
232
|
+
|
|
233
|
+
**Severity:** High
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Anti-Pattern 10: Avoiding Abstractions "for Performance"
|
|
238
|
+
|
|
239
|
+
**Also known as:** Abstraction allergy, Concrete-only coding
|
|
240
|
+
|
|
241
|
+
**Description:** Refusing to use interfaces, virtual methods, dependency injection, or polymorphism because "virtual dispatch is slow" or "indirection costs cycles." This produces tightly coupled, hard-to-test monolithic code.
|
|
242
|
+
|
|
243
|
+
**Why it happens:** Reading benchmarks that show virtual dispatch costs 1-2 nanoseconds more than a direct call and extrapolating that to system-level impact; confusing microbenchmark results with application-level performance.
|
|
244
|
+
|
|
245
|
+
**Real-world consequences:** A team avoided dependency injection in a payment service because "constructing the DI container is overhead." The result was a 15,000-line class with hardcoded dependencies that could not be unit tested. Finding bugs required deploying to staging and running end-to-end tests, turning a 5-minute feedback loop into a 45-minute one. The total developer-hours lost to slow testing dwarfed any theoretical nanosecond savings from avoiding DI.
|
|
246
|
+
|
|
247
|
+
**The fix:**
|
|
248
|
+
- Virtual dispatch costs 1-5ns. A single network call costs 500,000-50,000,000ns. Optimize the network call first.
|
|
249
|
+
- Use abstractions to enable testability and modularity.
|
|
250
|
+
- If profiling shows virtual dispatch is a bottleneck (extremely rare), devirtualize that specific call site -- do not eliminate all abstractions.
|
|
251
|
+
|
|
252
|
+
**Detection signals:**
|
|
253
|
+
- Classes with 1,000+ lines and zero interfaces.
|
|
254
|
+
- Comments like "// avoiding interface for perf."
|
|
255
|
+
- No unit tests because the code cannot be mocked or injected.
|
|
256
|
+
|
|
257
|
+
**Severity:** High
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Anti-Pattern 11: Premature Parallelization
|
|
262
|
+
|
|
263
|
+
**Also known as:** Thread-it-first, Concurrency cargo cult
|
|
264
|
+
|
|
265
|
+
**Description:** Introducing multithreading, async/await, worker pools, or parallel streams before establishing that the workload is CPU-bound, large enough to benefit from parallelism, and that the overhead of thread coordination does not exceed the gain.
|
|
266
|
+
|
|
267
|
+
**Why it happens:** Belief that "more cores = more speed" without understanding Amdahl's Law; async/await being easy to write leading to its use where it adds complexity for no throughput gain.
|
|
268
|
+
|
|
269
|
+
**Real-world consequences:** A data pipeline team parallelized a CSV import that processed 500 records in 200ms. The parallel version processed the same 500 records in 180ms but introduced a race condition that silently dropped records when two threads wrote to the same output buffer. The bug was discovered three months later when an audit revealed 2% data loss. The parallel overhead (thread creation, synchronization, error aggregation) made the code five times harder to debug.
|
|
270
|
+
|
|
271
|
+
**The fix:**
|
|
272
|
+
- Parallelism helps when: (a) the workload is CPU-bound, (b) the dataset is large enough that coordination overhead is amortized, and (c) tasks are independent.
|
|
273
|
+
- Measure single-threaded performance first. If it meets the target, stop.
|
|
274
|
+
- Use parallel streams or `Parallel.ForEach` only after benchmarking shows >2x improvement.
|
|
275
|
+
- Never parallelize I/O-bound work by adding threads -- use async I/O instead.
|
|
276
|
+
|
|
277
|
+
**Detection signals:**
|
|
278
|
+
- `CompletableFuture`, `Parallel.ForEach`, `goroutine`, or thread pool usage for operations completing in <100ms.
|
|
279
|
+
- Race conditions or data corruption bugs in the issue tracker.
|
|
280
|
+
- Parallelized code that processes fewer than 1,000 items.
|
|
281
|
+
|
|
282
|
+
**Severity:** Critical
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Anti-Pattern 12: Object Pooling When GC Handles It Fine
|
|
287
|
+
|
|
288
|
+
**Also known as:** Pool-everything, Allocation fear
|
|
289
|
+
|
|
290
|
+
**Description:** Creating explicit object pools for lightweight, short-lived objects in garbage-collected runtimes where the GC's young-generation collection is specifically optimized for exactly this allocation pattern.
|
|
291
|
+
|
|
292
|
+
**Why it happens:** Legacy advice from Java 1.2 era (when GC was genuinely slow) still circulating in blogs and books; observing GC metrics without understanding that young-gen collections are designed to be cheap.
|
|
293
|
+
|
|
294
|
+
**Real-world consequences:** Oracle's official Java performance guidance explicitly warns against unnecessary pooling: "Because pooled objects are in the old generation, there is an additional cost of re-use including time required to clean the pooled objects; temporary objects created with references to the older generation add to the cost of young GCs; and the older collector must inspect pooled objects during every collection cycle, adding constant overhead." Additionally, object reuse can introduce hard-to-debug state-leakage errors.
|
|
295
|
+
|
|
296
|
+
**The fix:**
|
|
297
|
+
- Pool only objects with expensive initialization: database connections, SSL contexts, thread-pool workers, large buffers.
|
|
298
|
+
- For ordinary DTOs, request objects, or response builders -- allocate and let the GC collect.
|
|
299
|
+
- Monitor GC pause times; if young-gen pauses are under 10ms, pooling adds no value.
|
|
300
|
+
- Modern JVMs (Java 21+ with ZGC) can handle hundreds of millions of allocations per second.
|
|
301
|
+
|
|
302
|
+
**Detection signals:**
|
|
303
|
+
- Pool classes for simple POJOs or value objects.
|
|
304
|
+
- `reset()` or `clear()` methods on pooled objects that have caused state-leakage bugs.
|
|
305
|
+
- GC pause times are already acceptable but pools exist "just in case."
|
|
306
|
+
|
|
307
|
+
**Severity:** Medium
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Anti-Pattern 13: Binary Protocols When JSON Is Fast Enough
|
|
312
|
+
|
|
313
|
+
**Also known as:** Protobuf-everywhere, Binary-first syndrome
|
|
314
|
+
|
|
315
|
+
**Description:** Adopting Protocol Buffers, MessagePack, FlatBuffers, or custom binary formats for internal APIs or low-throughput services where JSON's human readability, tooling ecosystem, and debuggability provide far more value than the performance delta.
|
|
316
|
+
|
|
317
|
+
**Why it happens:** Reading benchmarks showing Protobuf is 5-8x faster than JSON for encoding/decoding and applying that without considering that serialization is rarely the bottleneck; wanting to appear "serious" about performance.
|
|
318
|
+
|
|
319
|
+
**Real-world consequences:** A team adopted Protobuf for all internal microservice communication. Debugging production issues became significantly harder because request/response payloads were opaque binary blobs. Engineers needed special tooling to decode messages. The actual serialization time was 0.5ms per request on average -- dwarfed by 50ms of business logic and 30ms of database access. When JSON was reintroduced for debug endpoints, the team discovered that modern JSON libraries (e.g., DSL-JSON, simdjson) closed the performance gap to 1.3-2x for encoding.
|
|
320
|
+
|
|
321
|
+
**The fix:**
|
|
322
|
+
- Use JSON for APIs with throughput under 10,000 requests/second and payload sizes under 1MB.
|
|
323
|
+
- Reserve binary protocols for: high-throughput data pipelines, large payload transfers, bandwidth-constrained mobile clients, or strict schema enforcement requirements.
|
|
324
|
+
- If you adopt a binary protocol, maintain human-readable debug endpoints or logging.
|
|
325
|
+
- Profile serialization overhead in context -- if it is <5% of request time, JSON is fine.
|
|
326
|
+
|
|
327
|
+
**Detection signals:**
|
|
328
|
+
- Protobuf/MessagePack used for admin APIs with <100 requests/minute.
|
|
329
|
+
- Engineers complaining they cannot read request logs.
|
|
330
|
+
- Special decoding tooling required to debug production issues.
|
|
331
|
+
|
|
332
|
+
**Severity:** Medium
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Anti-Pattern 14: Compression on Small Payloads
|
|
337
|
+
|
|
338
|
+
**Also known as:** Gzip-everything, Compress-by-default
|
|
339
|
+
|
|
340
|
+
**Description:** Applying gzip, Brotli, or zstd compression to HTTP responses or messages smaller than 1KB, where the compression overhead (CPU time, header bytes) exceeds the bandwidth saved and can actually increase the total payload size.
|
|
341
|
+
|
|
342
|
+
**Why it happens:** Enabling compression globally in a web server or framework without setting a minimum size threshold; assuming compression always helps.
|
|
343
|
+
|
|
344
|
+
**Real-world consequences:** GZip adds a minimum of 18 bytes of header overhead plus CPU processing time of 1-2ms per compression. For a 200-byte JSON response, the "compressed" output can be larger than the original. A team enabled gzip globally on their API gateway and discovered that for their most common response (a 150-byte health check called 1,000 times/second), compression added 1.5ms latency per call while saving zero bytes -- the compressed output was actually 4 bytes larger.
|
|
345
|
+
|
|
346
|
+
**The fix:**
|
|
347
|
+
- Set a minimum compression threshold: 1KB for gzip, 512 bytes for Brotli.
|
|
348
|
+
- Exclude small, fixed-size responses (health checks, acknowledgments, status codes).
|
|
349
|
+
- Measure compression ratio for your actual response distribution.
|
|
350
|
+
- Consider pre-compression for static assets rather than runtime compression.
|
|
351
|
+
|
|
352
|
+
**Detection signals:**
|
|
353
|
+
- Global compression enabled with no minimum size configured.
|
|
354
|
+
- Compression applied to health-check or ping endpoints.
|
|
355
|
+
- CPU profiling shows compression/decompression appearing in the flame graph for small payloads.
|
|
356
|
+
|
|
357
|
+
**Severity:** Low
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Anti-Pattern 15: Pre-Computing Everything at Startup
|
|
362
|
+
|
|
363
|
+
**Also known as:** Eager initialization syndrome, Startup bloat
|
|
364
|
+
|
|
365
|
+
**Description:** Computing and caching all possible results, configurations, lookup tables, or derived data at application startup rather than lazily computing them on first access. This inflates startup time, wastes memory on never-accessed results, and delays deployment rollouts.
|
|
366
|
+
|
|
367
|
+
**Why it happens:** Desire to make all runtime accesses O(1); fear of lazy-init race conditions; not tracking which pre-computed values are actually accessed.
|
|
368
|
+
|
|
369
|
+
**Real-world consequences:** A recommendation service pre-computed similarity scores for all 2 million product pairs at startup. Startup took 12 minutes. In practice, only 3% of product pairs were ever queried. The 12-minute startup time meant that deployments took 25 minutes (including health checks), which slowed the deployment pipeline, discouraged frequent releases, and delayed hotfixes. Switching to lazy computation with an LRU cache reduced startup to 15 seconds and memory usage by 85%.
|
|
370
|
+
|
|
371
|
+
**The fix:**
|
|
372
|
+
- Use lazy initialization with caching for expensive computations.
|
|
373
|
+
- Track access patterns to identify which pre-computations are actually used.
|
|
374
|
+
- Limit startup pre-computation to data that is (a) always needed, (b) cheap to compute in bulk, and (c) expensive to compute individually.
|
|
375
|
+
- Set a startup time budget (e.g., <30 seconds) and enforce it.
|
|
376
|
+
|
|
377
|
+
**Detection signals:**
|
|
378
|
+
- Application startup time exceeding 60 seconds.
|
|
379
|
+
- Large memory allocation during initialization that remains constant.
|
|
380
|
+
- Monitoring shows many pre-computed values are never accessed.
|
|
381
|
+
- Deployment pipeline blocked by slow-starting instances.
|
|
382
|
+
|
|
383
|
+
**Severity:** High
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Anti-Pattern 16: Avoiding Exceptions "for Performance"
|
|
388
|
+
|
|
389
|
+
**Also known as:** Exception phobia, Return-code-everywhere
|
|
390
|
+
|
|
391
|
+
**Description:** Replacing exception-based error handling with return codes, sentinel values, or boolean flags throughout the codebase because "exceptions are slow" -- even in code paths that are not performance-critical or where errors are truly exceptional.
|
|
392
|
+
|
|
393
|
+
**Why it happens:** Benchmark data showing exceptions are 100-650x slower than normal returns when thrown frequently; applying this data to all code paths regardless of error frequency.
|
|
394
|
+
|
|
395
|
+
**Real-world consequences:** Microsoft's own .NET design guidelines distinguish between the two cases: exceptions thrown in common, expected scenarios (use Try-Parse pattern) versus exceptions for truly exceptional conditions (use exceptions). A team eliminated all exceptions from their C# API, replacing them with `Result<T>` tuples everywhere. The code became verbose, error handling was inconsistent (some callers forgot to check the result), and a swallowed error in payment processing caused silent failures for 48 hours. The try-catch version would have surfaced the error immediately via the global exception handler.
|
|
396
|
+
|
|
397
|
+
**The fix:**
|
|
398
|
+
- Use exceptions for truly exceptional conditions (network failures, invalid state, contract violations).
|
|
399
|
+
- Use the Try-Parse pattern (`bool TryParse(input, out result)`) for operations that fail frequently and are in hot paths.
|
|
400
|
+
- Do not replace all exceptions with return codes -- this is a different anti-pattern (error swallowing).
|
|
401
|
+
- Profile to determine if exception cost is material: if a path throws exceptions <1% of the time, the overhead is unmeasurable.
|
|
402
|
+
|
|
403
|
+
**Detection signals:**
|
|
404
|
+
- `Result<T>` or `Either<Error, T>` used for I/O errors that already have well-defined exceptions.
|
|
405
|
+
- Return-code checking boilerplate exceeding actual business logic in line count.
|
|
406
|
+
- Silent failures in production due to unchecked error return values.
|
|
407
|
+
|
|
408
|
+
**Severity:** Medium
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## Anti-Pattern 17: String Interning When Not Needed
|
|
413
|
+
|
|
414
|
+
**Also known as:** Intern-everything, String pool abuse
|
|
415
|
+
|
|
416
|
+
**Description:** Manually calling `String.intern()` (Java) or `string.Intern()` (.NET) on strings that are not heavily duplicated or compared, adding lookup overhead and preventing garbage collection of those strings.
|
|
417
|
+
|
|
418
|
+
**Why it happens:** Reading that interning saves memory through deduplication and applying it broadly without measuring duplication rates.
|
|
419
|
+
|
|
420
|
+
**Real-world consequences:** Java performance engineer Aleksey Shipilev demonstrated that `String.intern()` is significantly slower due to native implementation overhead and time spent in StringTable operations. A benchmark showed interning was 75% slower than non-interning when applied broadly. Interned strings are held in a special pool that is not easily garbage collected, leading to effective memory leaks when many unique strings are interned. Removing `String.intern()` from hot paths has been a "profitable performance optimization in almost every project" Shipilev reviewed.
|
|
421
|
+
|
|
422
|
+
**The fix:**
|
|
423
|
+
- Use JVM flag `-XX:+UseStringDeduplication` (G1 GC) for automatic, safe deduplication.
|
|
424
|
+
- Manually intern only when: (a) the same string value appears thousands of times, (b) identity comparison (`==`) is needed instead of `.equals()`, and (c) the interned set is bounded and small.
|
|
425
|
+
- Profile memory before and after interning to confirm benefit.
|
|
426
|
+
- In .NET, prefer a custom `ConcurrentDictionary`-based cache over `string.Intern()` for controllable lifetime.
|
|
427
|
+
|
|
428
|
+
**Detection signals:**
|
|
429
|
+
- `.intern()` calls in loops or request-handling code.
|
|
430
|
+
- Growing memory usage traced to the string intern pool.
|
|
431
|
+
- `StringTable` or intern pool appearing in GC analysis.
|
|
432
|
+
|
|
433
|
+
**Severity:** Medium
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## Anti-Pattern 18: Inlining Everything
|
|
438
|
+
|
|
439
|
+
**Also known as:** Inline-all, Function elimination mania
|
|
440
|
+
|
|
441
|
+
**Description:** Marking functions as `inline`, `@inline`, `[MethodImpl(AggressiveInlining)]`, or manually copy-pasting function bodies to avoid call overhead, without considering code bloat and instruction cache pressure.
|
|
442
|
+
|
|
443
|
+
**Why it happens:** Knowing that function call overhead is "wasted cycles" and extrapolating that eliminating all calls will be faster; not understanding that modern compilers already inline small functions automatically.
|
|
444
|
+
|
|
445
|
+
**Real-world consequences:** Excessive inlining duplicates the function body at every call site. If a function is inlined in N places, N copies exist in the binary. When code size exceeds the instruction cache (L1i is typically 32-64KB per core), cache misses occur, causing stalls that are far more expensive than the function call overhead that inlining was meant to avoid. Research on compiler inlining confirms: "As a rule of thumb, some inlining will improve speed at very minor cost of space, but excess inlining will hurt speed, due to inlined code consuming too much of the instruction cache."
|
|
446
|
+
|
|
447
|
+
**The fix:**
|
|
448
|
+
- Let the compiler decide. Modern compilers (GCC, Clang, MSVC, JIT compilers) have sophisticated inlining heuristics that consider function size, call frequency, and cache impact.
|
|
449
|
+
- Manual inline hints should be reserved for small (1-5 line), hot functions that profiling shows the compiler failed to inline.
|
|
450
|
+
- Never inline functions larger than ~20 lines.
|
|
451
|
+
- Measure binary size and instruction cache miss rate after aggressive inlining.
|
|
452
|
+
|
|
453
|
+
**Detection signals:**
|
|
454
|
+
- `inline` keyword or `forceinline` on functions with 20+ lines.
|
|
455
|
+
- Binary size growth after "optimization" pass.
|
|
456
|
+
- Instruction cache miss rate increasing in hardware performance counters.
|
|
457
|
+
- Copy-pasted function bodies with comments like "// inlined for speed."
|
|
458
|
+
|
|
459
|
+
**Severity:** Medium
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## Anti-Pattern 19: Loop Unrolling in Application Code
|
|
464
|
+
|
|
465
|
+
**Also known as:** Manual unroll, Compiler-doesn't-know-best
|
|
466
|
+
|
|
467
|
+
**Description:** Manually unrolling loops (writing `a[0]=x; a[1]=x; a[2]=x; a[3]=x;` instead of a for-loop) in application-level code, believing this will be faster than what the compiler produces.
|
|
468
|
+
|
|
469
|
+
**Why it happens:** Reading about loop unrolling as a compiler optimization technique and attempting to do the compiler's job manually; habits from HPC or embedded contexts applied to web/business applications.
|
|
470
|
+
|
|
471
|
+
**Real-world consequences:** Modern compilers at `-O2` or higher automatically unroll loops when beneficial, considering factors like trip count, body complexity, register pressure, and vectorization opportunities. Manual unrolling often actively interferes with the compiler's analysis: "There has been a great deal of clutter introduced into old dusty-deck FORTRAN programs in the name of loop unrolling that now serves only to confuse and mislead today's compilers." A manually unrolled loop is also a maintenance nightmare -- changing the logic requires updating every unrolled copy.
|
|
472
|
+
|
|
473
|
+
**The fix:**
|
|
474
|
+
- Compile with optimization flags (`-O2` or `-O3`) and let the compiler unroll.
|
|
475
|
+
- If a specific loop is a measured hotspot, use compiler pragmas (`#pragma unroll`) to hint rather than manually unrolling.
|
|
476
|
+
- Never manually unroll loops in Python, JavaScript, Java, or other interpreted/JIT-compiled languages -- the runtime handles this.
|
|
477
|
+
- If you must hand-unroll (e.g., SIMD intrinsics in C), isolate it behind a function boundary and benchmark.
|
|
478
|
+
|
|
479
|
+
**Detection signals:**
|
|
480
|
+
- Repeated identical statements that are clearly an unrolled loop.
|
|
481
|
+
- Comments like "// unrolled for performance" in application code.
|
|
482
|
+
- Loop bodies duplicated 4x or 8x with only index changes.
|
|
483
|
+
|
|
484
|
+
**Severity:** Low to Medium
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## Anti-Pattern 20: Premature Scaling
|
|
489
|
+
|
|
490
|
+
**Also known as:** Design-for-millions syndrome, Netflix-but-for-50-users
|
|
491
|
+
|
|
492
|
+
**Description:** Architecting a system for millions of concurrent users, petabytes of data, or global multi-region deployment when the current user base is measured in hundreds. This includes adopting microservices, event sourcing, CQRS, Kubernetes, and distributed databases before the monolith has been proven insufficient.
|
|
493
|
+
|
|
494
|
+
**Why it happens:** Aspirational architecture; reading scaling case studies from FAANG companies and copying their solutions without their problems; fear that "it won't scale" if not designed for scale from day one; conference-driven development.
|
|
495
|
+
|
|
496
|
+
**Real-world consequences:** Many early-stage startups adopt microservices because "that's what Netflix does" without considering that Netflix has thousands of engineers and problems most companies will never face. Teams end up spending enormous amounts of engineering time managing deployment pipelines, service discovery, distributed tracing, and eventual consistency when they could have been building features on a simple monolith. A single $20-50/month VPS can comfortably handle the first 100 users. Multiple startups have reported that premature scaling was a contributing factor in their failure -- they ran out of runway building infrastructure instead of product.
|
|
497
|
+
|
|
498
|
+
**The fix:**
|
|
499
|
+
- Start with a modular monolith. Extract services only when a specific module has different scaling requirements that are measured, not predicted.
|
|
500
|
+
- Every architectural decision should be reversible and made based on actual, measured pain points.
|
|
501
|
+
- Set scaling triggers: "When we hit X concurrent users / Y requests per second / Z data volume, we will evaluate extracting service A."
|
|
502
|
+
- A monolith deployed on a $50/month server with a managed database can serve 10,000+ users. Kubernetes costs more than that in engineering time alone.
|
|
503
|
+
|
|
504
|
+
**Detection signals:**
|
|
505
|
+
- Kubernetes in production for <1,000 users.
|
|
506
|
+
- More microservices than engineers.
|
|
507
|
+
- Distributed tracing, service mesh, or event bus for <10 services.
|
|
508
|
+
- Infrastructure cost exceeding application development cost in a pre-revenue startup.
|
|
509
|
+
|
|
510
|
+
**Severity:** Critical
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
## Root Cause Analysis
|
|
515
|
+
|
|
516
|
+
Premature optimization anti-patterns stem from five recurring root causes:
|
|
517
|
+
|
|
518
|
+
### 1. Absence of Measurement Culture
|
|
519
|
+
Teams that do not profile, benchmark, or monitor before optimizing will always optimize the wrong thing. Without data, developers rely on intuition, which is wrong the majority of the time.
|
|
520
|
+
|
|
521
|
+
**Countermeasure:** Make "show me the benchmark" a required element of any PR that claims a performance improvement. Integrate profiling into the development workflow, not just production monitoring.
|
|
522
|
+
|
|
523
|
+
### 2. Cargo-Culting Scale Solutions
|
|
524
|
+
Reading about how Google, Netflix, or Amazon solved problems at their scale and applying those solutions to a 500-user app. These companies publish their architectures for recruitment marketing, not as prescriptive guidance for all software.
|
|
525
|
+
|
|
526
|
+
**Countermeasure:** Before adopting any "scale" technology, ask: "What specific, measured problem does this solve for us today?" If the answer is "nothing yet," defer it.
|
|
527
|
+
|
|
528
|
+
### 3. Confusing Asymptotic Complexity with Real Performance
|
|
529
|
+
Choosing O(log n) over O(n) for n=20 ignores constant factors, cache effects, and branch prediction. Big-O notation describes behavior as n approaches infinity -- it says nothing about small n.
|
|
530
|
+
|
|
531
|
+
**Countermeasure:** Benchmark with realistic dataset sizes. For small n, prefer simpler data structures with better cache locality.
|
|
532
|
+
|
|
533
|
+
### 4. Legacy Performance Folklore
|
|
534
|
+
Advice that was valid in 2005 (object pooling in Java 1.4, manual loop unrolling, avoiding virtual dispatch) is still circulating in blogs, books, and Stack Overflow answers. Modern runtimes, compilers, and hardware have invalidated much of this advice.
|
|
535
|
+
|
|
536
|
+
**Countermeasure:** Date-check performance advice. If the benchmark was run on Java 6 or gcc 4.x, re-evaluate with modern toolchains.
|
|
537
|
+
|
|
538
|
+
### 5. Optimizing for Developer Ego Instead of User Experience
|
|
539
|
+
Some optimizations are done because they are intellectually stimulating or impressive in code review, not because they improve the user experience. Bit manipulation tricks, lock-free data structures, and custom allocators are more fun to write than a well-indexed SQL query -- but the query is what the user is waiting for.
|
|
540
|
+
|
|
541
|
+
**Countermeasure:** Define performance from the user's perspective (latency, throughput, responsiveness) and optimize only metrics that users experience.
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
## Self-Check Questions
|
|
546
|
+
|
|
547
|
+
Ask these questions before any optimization work:
|
|
548
|
+
|
|
549
|
+
1. **Have I profiled?** Can I point to a flame graph, profiler output, or benchmark showing this is a hotspot?
|
|
550
|
+
2. **What percentage of total time does this code path consume?** If <5%, optimizing it cannot improve overall performance by more than 5%.
|
|
551
|
+
3. **What is the expected improvement?** Can I state a specific target (e.g., "reduce p95 latency from 800ms to 400ms")?
|
|
552
|
+
4. **Does this optimization sacrifice readability?** If a new team member cannot understand the optimized code in 5 minutes, the maintenance cost may exceed the performance gain.
|
|
553
|
+
5. **Does this optimization sacrifice correctness?** Any optimization that introduces subtle bugs is a net negative regardless of speed improvement.
|
|
554
|
+
6. **Am I optimizing for current scale or imagined future scale?** If the system does not yet have the load that would trigger the problem, defer the optimization.
|
|
555
|
+
7. **Is the compiler/runtime already doing this?** Check whether the JIT, optimizer, or standard library already handles this case.
|
|
556
|
+
8. **What is the total cost?** Include implementation time, testing time, review time, maintenance burden, and cognitive load -- not just the performance delta.
|
|
557
|
+
9. **Can I easily revert this?** Optimizations that change data formats, protocols, or schemas are much harder to undo than code-level changes.
|
|
558
|
+
10. **Have I measured after?** Did the optimization actually produce the expected improvement in production, not just in a microbenchmark?
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## Code Smell Quick Reference
|
|
563
|
+
|
|
564
|
+
| Smell | Anti-Pattern | Severity |
|
|
565
|
+
|---|---|---|
|
|
566
|
+
| PR says "optimize" with no benchmark attached | #1 Optimizing Without Profiling | High |
|
|
567
|
+
| Bit shifts in business logic | #8 Bit Manipulation Theater | Medium |
|
|
568
|
+
| `inline` or `forceinline` on 50-line functions | #18 Inlining Everything | Medium |
|
|
569
|
+
| `String.intern()` in request-handling code | #17 Unnecessary String Interning | Medium |
|
|
570
|
+
| `System.gc()` or `GC.Collect()` in production | #9 Custom Memory Management in GC | High |
|
|
571
|
+
| Object pool for simple DTOs | #12 Unnecessary Object Pooling | Medium |
|
|
572
|
+
| Protobuf for admin API with 10 req/min | #13 Binary Protocol Overkill | Medium |
|
|
573
|
+
| Gzip enabled on 100-byte health check responses | #14 Compression on Small Payloads | Low |
|
|
574
|
+
| `@Cacheable` on a function that returns `new Date()` | #3 Caching Everything | High |
|
|
575
|
+
| Same column in 5+ database tables | #4 Premature Denormalization | Critical |
|
|
576
|
+
| Kubernetes for 200-user app | #20 Premature Scaling | Critical |
|
|
577
|
+
| `HashMap` for 10-item config | #5 Complex Structures for Small Data | Low |
|
|
578
|
+
| Custom URL parser replacing `java.net.URI` | #6 Hand-Rolling Standard Library | High |
|
|
579
|
+
| `CompletableFuture` for 50-item list | #11 Premature Parallelization | Critical |
|
|
580
|
+
| Manually unrolled loop with 8 copies | #19 Loop Unrolling in App Code | Low |
|
|
581
|
+
| 12-minute startup computing all possible results | #15 Pre-Computing Everything | High |
|
|
582
|
+
| Zero interfaces in 5,000-line service class | #10 Avoiding Abstractions | High |
|
|
583
|
+
| `Result<T>` replacing all try-catch blocks | #16 Avoiding Exceptions | Medium |
|
|
584
|
+
| Thread pool for operation completing in 5ms | #11 Premature Parallelization | Critical |
|
|
585
|
+
| Custom sort function "for speed" | #6 Hand-Rolling Standard Library | High |
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
## The Decision Framework: When Optimization IS Appropriate
|
|
590
|
+
|
|
591
|
+
Not all optimization is premature. Optimization is warranted when:
|
|
592
|
+
|
|
593
|
+
1. **Profiling data identifies a clear hotspot** consuming >20% of total time.
|
|
594
|
+
2. **Users are experiencing measurable pain** (latency complaints, timeout errors, dropped requests).
|
|
595
|
+
3. **The system is approaching a known scaling cliff** (database connection exhaustion, memory limits, thread pool saturation) with growth data to project when the cliff will be hit.
|
|
596
|
+
4. **The optimization preserves or improves readability** (better algorithms are often both faster and clearer).
|
|
597
|
+
5. **The critical 3%** -- Knuth's full quote acknowledges that there are cases where optimization matters. The key is identifying those cases through measurement, not intuition.
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## Sources
|
|
602
|
+
|
|
603
|
+
- [Donald Knuth, "Structured Programming with go to Statements" (1974)](https://en.wikiquote.org/wiki/Donald_Knuth) -- origin of the "premature optimization is the root of all evil" quote
|
|
604
|
+
- [The Sad Tragedy of Micro-Optimization Theater -- Coding Horror](https://blog.codinghorror.com/the-sad-tragedy-of-micro-optimization-theater/) -- Jeff Atwood on micro-optimization futility
|
|
605
|
+
- [The Fallacy of Premature Optimization -- ACM Ubiquity](https://ubiquity.acm.org/article.cfm?id=1513451) -- analysis of misinterpretation of Knuth's quote
|
|
606
|
+
- [Premature Optimization is Still the Root of All Evil -- Daniel Tunkelang](https://dtunkelang.medium.com/premature-optimization-is-still-the-root-of-all-evil-a3502c2ea262) -- modern restatement
|
|
607
|
+
- [Why Premature Optimization Is the Root of All Evil -- Stackify](https://stackify.com/premature-optimization-evil/) -- practical examples and case studies
|
|
608
|
+
- [Premature Optimization -- Effectiviology](https://effectiviology.com/premature-optimization/) -- cognitive biases driving premature optimization
|
|
609
|
+
- [Why Premature Optimization Hides Deeper Architectural Debt -- Technori](https://technori.com/news/premature-optimization-architectural-debt/) -- caching-as-contract case study
|
|
610
|
+
- [JVM Anatomy Quark #10: String.intern() -- Aleksey Shipilev](https://shipilev.net/jvm/anatomy-quarks/10-string-intern/) -- authoritative analysis of String.intern() performance
|
|
611
|
+
- [String Interning Performance Impact -- yCrash](https://blog.ycrash.io/java-string-intern-performance-impact/) -- benchmarks showing intern overhead
|
|
612
|
+
- [Inline Expansion -- Wikipedia](https://en.wikipedia.org/wiki/Inline_expansion) -- inlining trade-offs and instruction cache effects
|
|
613
|
+
- [What Happens If We Inline Everything? -- Stefanos Baziotis](https://sbaziotis.com/compilers/what-happens-if-we-inline-everything.html) -- analysis of excessive inlining
|
|
614
|
+
- [Oracle: Improving Java Performance by Reducing GC Times](https://www.oracle.com/technical-resources/articles/java/garbagecollection-in-java-applications.html) -- official Oracle guidance on object pooling costs
|
|
615
|
+
- [Potential Pitfalls in Data and Task Parallelism -- Microsoft](https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/potential-pitfalls-in-data-and-task-parallelism) -- over-parallelization documentation
|
|
616
|
+
- [Exceptions and Performance -- Microsoft .NET Design Guidelines](https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/exceptions-and-performance) -- Try-Parse pattern guidance
|
|
617
|
+
- [The GZIP Penalty -- Joe Honton](https://joehonton.medium.com/the-gzip-penalty-d31bd697f1a2) -- compression overhead on small payloads
|
|
618
|
+
- [Anti-Patterns by Example: Premature Optimization -- Thiago Ricieri](https://medium.com/@thiagoricieri/anti-patterns-by-example-premature-optimization-f46056dd1e39) -- catalog of premature optimization examples
|
|
619
|
+
- [Not All Optimization Is Premature -- Bozhidar Bozhanov](https://techblog.bozho.net/not-all-optimization-is-premature-4/) -- balanced perspective on when optimization is appropriate
|
|
620
|
+
- [Premature Optimization: Stop Over-Engineering -- Qt](https://qt.io/quality-assurance/blog/premature-optimization) -- engineering process perspective
|
|
621
|
+
- [Loop Unrolling -- Wikipedia](https://en.wikipedia.org/wiki/Loop_unrolling) -- compiler auto-unrolling and manual unrolling trade-offs
|
|
622
|
+
- [Protobuf vs JSON: Performance Benchmarks](https://jsontotable.org/blog/protobuf/protobuf-vs-json) -- serialization performance comparisons
|
|
623
|
+
- [An Empirical Study of Optimization Bugs in GCC and LLVM -- ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0164121220302740) -- research on compiler optimization bugs
|