Hello World
Your First Program
Create a file called hello.ts:
// demonstrates: the minimal Perry program in the docs
// docs: docs/src/getting-started/hello-world.md
// platforms: macos, linux, windows
// targets: wasm, web, android
console.log("Hello, Perry!")
Compile and run it:
perry hello.ts -o hello
./hello
Output:
Hello, Perry!
That’s it. Perry compiled your TypeScript to a native executable — no Node.js, no bundler, no runtime.
A Slightly Bigger Example
// demonstrates: recursive fib as a perf-vs-node talking point
// docs: docs/src/getting-started/hello-world.md
// platforms: macos, linux, windows
// targets: wasm, web, android
function fibonacci(n: number): number {
if (n <= 1) return n
return fibonacci(n - 1) + fibonacci(n - 2)
}
const start = Date.now()
const result = fibonacci(35)
const elapsed = Date.now() - start
console.log(`fibonacci(35) = ${result}`)
console.log(`Completed in ${elapsed}ms`)
perry fib.ts -o fib
./fib
This runs about 2x faster than Node.js because Perry compiles to native machine code with integer specialization.
Using Variables and Functions
const name: string = "World"
const items: number[] = [1, 2, 3, 4, 5]
const doubled = items.map((x) => x * 2)
const sum = doubled.reduce((acc, x) => acc + x, 0)
console.log(`Hello, ${name}!`)
console.log(`Sum of doubled: ${sum}`)
Async Code
// demonstrates: async/await fetch shown in hello-world.md
// docs: docs/src/getting-started/hello-world.md
// platforms: macos, linux, windows
// run: false
async function fetchData(): Promise<string> {
const response = await fetch("https://httpbin.org/get")
const data = await response.json() as { origin: string }
return data.origin
}
const ip = await fetchData()
console.log(`Your IP: ${ip}`)
perry fetch.ts -o fetch
./fetch
Perry compiles async/await to a native async runtime backed by Tokio.
Multi-Threading
Perry can do something no JavaScript runtime can — run your code on multiple CPU cores:
// demonstrates: parallelMap + spawn shown in hello-world.md
// docs: docs/src/getting-started/hello-world.md
// platforms: macos, linux, windows
import { parallelMap, parallelFilter, spawn } from "perry/thread"
const data = [1, 2, 3, 4, 5, 6, 7, 8]
// Process all elements across all CPU cores
const doubled = parallelMap(data, (x: number) => x * 2)
console.log(doubled) // [2, 4, 6, 8, 10, 12, 14, 16]
// Run heavy work in the background
const result = await spawn(() => {
let sum = 0
for (let i = 0; i < 100_000_000; i++) sum += i
return sum
})
console.log(result)
// parallelFilter is also available for the lift-and-parallelize case:
const evens = parallelFilter(data, (x: number) => x % 2 === 0)
console.log(evens)
This is real OS-level parallelism, not web workers or separate isolates. See Multi-Threading for details.
What the Compiler Produces
When you run perry file.ts -o output, Perry:
- Parses your TypeScript with SWC
- Lowers the AST to an intermediate representation (HIR)
- Applies optimizations (inlining, closure conversion, etc.)
- Generates native machine code with LLVM
- Links with your system’s C compiler
The result is a standalone executable with no external dependencies.
Binary Size
| Program | Binary Size |
|---|---|
| Hello world | ~300KB |
| CLI with fs/path | ~3MB |
| UI app | ~3MB |
| Full app with stdlib | ~48MB |
Perry automatically detects which runtime features you use and only links what’s needed.