Skip to content

Conversation

@dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Jan 6, 2026

Summary

TL;DR: Native TypeScript compiler delivers 5-6x faster local builds and 33% faster CI builds, but we won't adopt it due to its experimental status and requirement for less strongly-typed decorator implementations. We'll revisit in v3 or when it becomes stable.

Performance Results

Local Development:

  • Clean builds: 6.15x faster (1,574ms → 256ms, 83.7% reduction)
  • Incremental builds: 5.55x faster (1,465ms → 264ms, 82% reduction)
  • Build consistency: 87-92% more predictable timing
  • Testing: 100 iterations per scenario with statistical analysis

CI Environment:

Technical Changes

  • Install @typescript/native-preview@7.0.0-dev.20260106.1
  • Remove baseUrl from all tsconfig.json files (not supported by native compiler)
  • Update all build scripts to use npx @typescript/native-preview
  • Fix import in layers/bin/layers.ts to use relative path with .js extension
  • Fix decorator type errors with (originalMethod as any).apply() - reduces type safety
  • Add proper return type annotations for BedrockFunctionResponse

Methodology

Local Testing:

  • Benchmarked @aws-lambda-powertools/commons package
  • 100 iterations per test scenario with 5 warmup runs
  • Measured both clean and incremental build scenarios
  • Statistical analysis with mean, median, standard deviation, percentiles

CI Analysis:

Decision Rationale

While performance improvements are substantial, we're not adopting the native compiler because:

  1. Experimental status - @typescript/native-preview is development/preview software
  2. Type safety regression - Requires as any casts in decorator implementations
  3. Stability concerns - Preview software may have breaking changes
  4. Risk vs benefit - Current build times are acceptable for development workflow

We'll reconsider adoption when:

  • Native compiler reaches stable release status, OR
  • We begin work on v3 of the project (whichever comes first)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Install @typescript/native-preview@7.0.0-dev.20260106.1
- Remove baseUrl from all tsconfig.json files (not supported by native compiler)
- Update all build scripts to use npx @typescript/native-preview
- Fix import in layers/bin/layers.ts to use relative path with .js extension
- Native compiler provides 5-6x faster compilation (256ms vs 1,574ms clean builds)
- Stricter type checking catches additional type errors
- Maintains compatibility with existing build system and project references
@dreamorosi dreamorosi self-assigned this Jan 6, 2026
@boring-cyborg boring-cyborg bot added dependencies Changes that touch dependencies, e.g. Dependabot, etc. internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) layers Items related to the Lambda Layers pipeline labels Jan 6, 2026
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Jan 6, 2026
The native TypeScript compiler has stricter type checking that catches
additional type errors in the codebase. Reverting to regular tsc while
keeping the baseUrl removal to test CI performance impact of configuration
changes alone.
@pull-request-size pull-request-size bot added size/XXL PRs with 1K+ LOC, largely documentation related and removed size/M PR between 30-99 LOC labels Jan 6, 2026
- Restore npx @typescript/native-preview usage in all build scripts
- Fix decorator type errors with (originalMethod as any).apply()
- Add proper return type annotation for BedrockFunctionResponse.build()
- Import BedrockAgentFunctionResponse type
- Native compiler now builds successfully with 5-6x performance improvement
@boring-cyborg boring-cyborg bot added event-handler This item relates to the Event Handler Utility logger This item relates to the Logger Utility metrics This item relates to the Metrics Utility labels Jan 6, 2026
let result: unknown;
try {
result = await originalMethod.apply(this, args);
result = await (originalMethod as any).apply(this, args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm presuming these are unavoidable with the extra strictness of the new compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to figure this out - I'm not keen on keeping the any, once we can drop support for legacy decorators (addressed in v3 discussion) the implementation here would change though.

@pull-request-size pull-request-size bot added size/M PR between 30-99 LOC and removed size/XXL PRs with 1K+ LOC, largely documentation related labels Jan 6, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2026

@dreamorosi
Copy link
Contributor Author

Closing for now, see PR body for details

@dreamorosi dreamorosi closed this Jan 6, 2026
@dreamorosi dreamorosi changed the title feat: adopt @typescript/native-preview compiler for 5-6x faster builds experiment: @typescript/native-preview compiler for 5-6x faster local builds, 33% faster CI Jan 6, 2026
@svozza
Copy link
Contributor

svozza commented Jan 6, 2026

Great deep dive @dreamorosi. I fully agree with your conclusions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Changes that touch dependencies, e.g. Dependabot, etc. event-handler This item relates to the Event Handler Utility internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) layers Items related to the Lambda Layers pipeline logger This item relates to the Logger Utility metrics This item relates to the Metrics Utility size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants