-
Notifications
You must be signed in to change notification settings - Fork 650
Improve memory usage of formatter #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bd6cc28
single file format cli for testing
weswigham c0f152a
Fix unguarded addition bug
weswigham 7c376dd
Add cli bench
weswigham c681b93
Make generic to avoid boxing
weswigham 668cfc3
Depointer TextRangeWithKind
weswigham 64a1c90
Swap tokenInfo from pointer to concrete
weswigham 92399cd
Use just one scratch space for iterating the current rules list
weswigham 64ea7e3
Remove actual format cli endpoint for now
weswigham 251955c
Fix lint
weswigham 859ca13
Remove somewhat duplicative benchmark
weswigham b95e219
Merge branch 'main' into fmt-test
weswigham a995e27
Update API
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package execute | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/microsoft/typescript-go/internal/bundled" | ||
"github.com/microsoft/typescript-go/internal/core" | ||
"github.com/microsoft/typescript-go/internal/repo" | ||
"github.com/microsoft/typescript-go/internal/tspath" | ||
"github.com/microsoft/typescript-go/internal/vfs" | ||
"github.com/microsoft/typescript-go/internal/vfs/osvfs" | ||
) | ||
|
||
func BenchmarkFormat(b *testing.B) { | ||
checkerPath := tspath.CombinePaths(repo.TypeScriptSubmodulePath, "src", "compiler", "checker.ts") | ||
|
||
tmp := b.TempDir() | ||
sys := newSystem() | ||
|
||
var count int | ||
|
||
b.ReportAllocs() | ||
time.Sleep(5 * time.Second) | ||
for b.Loop() { | ||
out := tspath.CombinePaths(tmp, fmt.Sprintf("out%d.ts", count)) | ||
code := fmtMain(sys, checkerPath, out) | ||
if code != 0 { | ||
b.Fatalf("Unexpected exit code: %d", code) | ||
} | ||
} | ||
} | ||
|
||
type osSys struct { | ||
writer io.Writer | ||
fs vfs.FS | ||
defaultLibraryPath string | ||
newLine string | ||
cwd string | ||
start time.Time | ||
} | ||
|
||
func (s *osSys) SinceStart() time.Duration { | ||
return time.Since(s.start) | ||
} | ||
|
||
func (s *osSys) Now() time.Time { | ||
return time.Now() | ||
} | ||
|
||
func (s *osSys) FS() vfs.FS { | ||
return s.fs | ||
} | ||
|
||
func (s *osSys) DefaultLibraryPath() string { | ||
return s.defaultLibraryPath | ||
} | ||
|
||
func (s *osSys) GetCurrentDirectory() string { | ||
return s.cwd | ||
} | ||
|
||
func (s *osSys) NewLine() string { | ||
return s.newLine | ||
} | ||
|
||
func (s *osSys) Writer() io.Writer { | ||
return s.writer | ||
} | ||
|
||
func (s *osSys) EndWrite() { | ||
// do nothing, this is needed in the interface for testing | ||
// todo: revisit if improving tsc/build/watch unittest baselines | ||
} | ||
|
||
func newSystem() *osSys { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error getting current directory: %v\n", err) | ||
os.Exit(int(ExitStatusInvalidProject_OutputsSkipped)) | ||
} | ||
|
||
return &osSys{ | ||
cwd: tspath.NormalizePath(cwd), | ||
fs: bundled.WrapFS(osvfs.FS()), | ||
defaultLibraryPath: bundled.LibPath(), | ||
writer: os.Stdout, | ||
newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"), | ||
start: time.Now(), | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.