Skip to content

feat: use TypeScript-go API - #69

Draft
acutmore wants to merge 8 commits into
mainfrom
ts-go
Draft

acutmore wants to merge 8 commits into
mainfrom
ts-go

Conversation

@acutmore

@acutmore acutmore commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

Just an experimental draft PR for now with the basics working.

Performance

The repo's perf test is currently showing 40% overhead on my M2 when using the native API

Using --cpu-prof to find hot spots and replace them with more efficient APIs the benchmark time has been improved from 1.641s to under a second and is now ~23% faster than main:

perf % ./bench.sh 
Benchmark 1: ts-blank-space
  Time (mean ± σ):     967.8 ms ±   9.2 ms    [User: 1370.5 ms, System: 160.8 ms]
  Range (min … max):   958.1 ms … 982.0 ms    10 runs
 
Benchmark 2: ts-blank-space@upstream
  Time (mean ± σ):      1.191 s ±  0.010 s    [User: 1.914 s, System: 0.091 s]
  Range (min … max):    1.178 s …  1.209 s    10 runs
 
Summary
  ts-blank-space ran
    1.23 ± 0.02 times faster than ts-blank-space@upstream

Note: this is with microsoft/typescript-go#4472 fixed locally, otherwise the current overhead is higher due to that extra walking caused by the bug. Now fixed upstream.

Output differences

Changes in AST Node start and end positions mean that more comments are being blanked out. Sometimes the output looks more correct, other times it would have been nice to preserve the comment. Using the scanner to get comment aware positions would likely address most of these.

This appears to be fixed upstream testing with @typescript/native-preview@7.0.0-dev.20260629.1 🎉

String position encoding bug

Non-ASCII characters are currently resulting in incorrect output due to the string position difference between Go (UTF-8) and JS (UTF-16).

microsoft/typescript-go#4289 did fix the issue for diagnostics. Maybe the same can be done for AST nodes too.

This appears to be fixed upstream testing with @typescript/native-preview@7.0.0-dev.20260629.1 🎉

acutmore added 2 commits June 29, 2026 21:22
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
acutmore added 3 commits July 2, 2026 09:06
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
acutmore added 2 commits July 5, 2026 15:47
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
Signed-off-by: Ashley Claymore <aclaymore@bloomberg.net>
@vanyauhalin

Copy link
Copy Markdown

Hi there. I'm not an active user of this library, unfortunately, but I'm keeping an eye on it because I love the idea behind it. Pure intereset. Are you considering rewriting it in Go since the TypeScript 7 is now in Go?

@acutmore

Copy link
Copy Markdown
Collaborator Author

Hi @vanyauhalin 👋🏻 thanks for taking an interest in the project!

Rewriting in Go is not something currently being considered.

I think this library provides the most benefit by being distributed as a small JavaScript package that can depend on the official TypeScript-Native package. The performance numbers are good and it keeps the package small and simple.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants