Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 4, 2025

Faster than doing a realpath + comparison.

goos: windows
goarch: amd64
pkg: github.com/microsoft/typescript-go/internal/vfs/osvfs
cpu: Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz
                                    │   out.txt   │
                                    │   sec/op    │
Realpath/target-20                    76.62µ ± 1%
Realpath/link-20                      87.68µ ± 2%
IsSymlinkOrJunction/regular_file-20   28.60µ ± 2%
IsSymlinkOrJunction/junction-20       22.62µ ± 2%
IsSymlinkOrJunction/nonexistent-20    11.45µ ± 0%
geomean                               34.63µ

                                    │  out.txt   │
                                    │    B/op    │
Realpath/target-20                    944.0 ± 0%
Realpath/link-20                      944.0 ± 0%
IsSymlinkOrJunction/regular_file-20   192.0 ± 0%
IsSymlinkOrJunction/junction-20       176.0 ± 0%
IsSymlinkOrJunction/nonexistent-20    192.0 ± 0%
geomean                               356.8

                                    │  out.txt   │
                                    │ allocs/op  │
Realpath/target-20                    8.000 ± 0%
Realpath/link-20                      8.000 ± 0%
IsSymlinkOrJunction/regular_file-20   1.000 ± 0%
IsSymlinkOrJunction/junction-20       1.000 ± 0%
IsSymlinkOrJunction/nonexistent-20    1.000 ± 0%
geomean                               2.297

Copilot AI review requested due to automatic review settings November 4, 2025 03:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors Windows junction and symlink detection by replacing the Realpath-based approach with a dedicated IsSymlinkOrJunction function. The change improves efficiency by using direct Windows API calls to check for reparse points instead of resolving full paths.

  • Adds platform-specific isSymlinkOrJunction implementations for Windows and Unix-like systems
  • Updates internal.Common struct to use IsSymlinkOrJunction instead of Realpath field
  • Simplifies junction detection logic in GetAccessibleEntries

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/vfs/osvfs/symlink_windows.go New file implementing Windows-specific junction/symlink detection using FILE_ATTRIBUTE_REPARSE_POINT
internal/vfs/osvfs/symlink_other.go New file with nil function stub for Unix-like systems where detection is unnecessary
internal/vfs/osvfs/os.go Updates osVFS initialization to use IsSymlinkOrJunction instead of Realpath
internal/vfs/internal/internal.go Replaces Realpath field with IsSymlinkOrJunction in Common struct and simplifies detection logic in GetAccessibleEntries

@DanielRosenwasser
Copy link
Member

Any specific differences you've seen in perf?

@jakebailey
Copy link
Member Author

Haven't tested yet, just cleaning up some TODOs with my name on it. On any project I have it probably won't be very noticable...

@jakebailey jakebailey marked this pull request as draft November 4, 2025 21:18
@jakebailey jakebailey marked this pull request as ready for review November 10, 2025 20:21
@jakebailey
Copy link
Member Author

To actually test this, I switched us over to the Microsoft fork of Go, which disables the SEH bit that auto-handles longpaths. I can split that out into its own PR for clarity if desired.

@jakebailey jakebailey enabled auto-merge November 10, 2025 21:47
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.

4 participants