[Repo Assist] perf: reuse stable temp file per document to reduce filesystem overhead#135
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
Instead of generating a random temp file name on every format call and deleting it afterwards, allocate one stable temp file path per document (keyed by document URI) on first use and overwrite it in-place on subsequent saves. Benefits: - Eliminates Math.random() + string manipulation on every save - Replaces create-then-delete with a single in-place overwrite, reducing OS inode churn when the user saves frequently - Predictable, PID-scoped names (phpcbf-<pid>-<n>.php) make temp files easier to identify and clean up if the process crashes Lifecycle: - Temp file is created on the first format of each document - Deleted in the onDidCloseTextDocument listener when the document closes - All remaining temp files are deleted synchronously in deactivate() The _phpcbf reference on exports is only for deactivation; it is not part of the public API. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
66 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 This is an automated PR from Repo Assist.
Problem
format()generates a fresh random temp file name on every save:This means every save causes:
Math.random()call + several string operations to build the nameFor users who save frequently (e.g. on every keystroke via
editor.formatOnSave), this creates constant inode churn in the OS temp directory.Fix
Allocate one stable temp file path per document (keyed by
document.uri.toString()) on first use, and overwrite it in-place on subsequent saves. Temp file names are nowphpcbf-(pid)-(n).php, scoped to the running process for easy identification.Lifecycle:
format()call for a documentonDidCloseTextDocumentwhen the user closes the tabdeactivate()Trade-offs
Mapentry + one file on disk per open PHP document); negligible in practicedeactivate(), a small number of temp files persist — same as the previous code, and the OS temp cleaner handles theseTest Status
Unit tests (
node --test test/unit.test.js): 7/7 passing ✅Syntax check (
node --check extension.js): OK ✅No CI workflow exists in this repository; all checks are manual.