Skip to content

Very slow Bun runtime startup with @ttsc/unplugin and Typia #969

Description

@iHaiduk

Environment

  • Bun: 1.3.14
  • ttsc: 0.20.0
  • @ttsc/unplugin: 0.20.0
  • Typia: 13.2.0
  • OS: macOS arm64

Problem

Using @ttsc/unplugin/bun as a Bun runtime plugin causes a very slow initial startup.

The application is a regular TypeScript application using Typia-generated validators.

Example runtime registration:

import typiaPlugin from "@ttsc/unplugin/bun";
import { plugin } from "bun";

plugin(typiaPlugin());

The application is started directly from a TypeScript entrypoint:

bun ./src/main.ts

On a cold process start, the first application log line may appear only after 1–5 minutes.

The same application starts almost immediately when running a prebuilt JavaScript bundle.

Disabling the Typia transform also starts quickly, but the application then fails because Typia requires its compile-time transformation.

Expected behavior

The Bun runtime plugin should provide one of the following:

  1. Transform only files required by the entrypoint.
  2. Reuse persistent or incremental compiler state.
  3. Provide a documented resident compiler or cache mode for development.

A normal development startup should complete within a few seconds without disabling Typia transformations.

Actual behavior

The first runtime import appears to trigger a project-wide TypeScript transformation.

The transformation is repeated after every process restart. The cache appears to be process-local, so it does not help when the development server is restarted.

Minimal reproduction

preload.ts:

import typiaPlugin from "@ttsc/unplugin/bun";
import { plugin } from "bun";

plugin(typiaPlugin());

bunfig.toml:

preload = ["./preload.ts"]

Start the application:

bun ./src/main.ts

Example Typia usage:

import typia from "typia";

export const validate = typia.createValidate<{ id: string }>();

Additional observations

  • Native Bun TypeScript startup without the Typia transform is fast.
  • A prebuilt bundle starts fast.
  • The delay occurs before application bootstrap code executes.
  • A resident TtscService was also tested, but it still compiled the full configured project.
  • A narrow tsconfig did not clearly limit the resident compilation scope.

Questions

  1. Is project-wide compilation expected for @ttsc/unplugin/bun in runtime mode?
  2. Is there a supported way to use a persistent resident compiler for Bun runtime loading?
  3. Can the runtime adapter use incremental per-file transformation instead of a full project transform?
  4. Can the project input set be restricted reliably to the entrypoint dependency graph?
  5. Is there a recommended development workflow for Bun and Typia that avoids multi-minute cold starts while preserving transformations?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions