-
Notifications
You must be signed in to change notification settings - Fork 499
RPC performance: sync receive queue and compact array format #6497
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
Open
knutwannheden
wants to merge
9
commits into
main
Choose a base branch
from
js-sync-rpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Optimizes RPC communication between Java and TypeScript for improved performance when processing large ASTs.
### Wire format change
Before (JSON objects):
```json
{"state":"ADD","valueType":"org.openrewrite.java.tree.J$Identifier","value":null,"ref":42}
```
After (compact arrays):
```json
[1,"org.openrewrite.java.tree.J$Identifier",null,42]
```
### Key changes
- **Sync receive queue**: Convert `RpcReceiveQueue` from async to sync by pre-fetching all data batches upfront, eliminating async/await overhead
- **Compact wire format**: Use compact arrays `[state, valueType, value, ref?, trace?]` instead of JSON objects for RPC messages in both directions
- **Benchmark support**: Add `reset()` methods for cache clearing between benchmark iterations
jkschneider
requested changes
Jan 10, 2026
| */ | ||
| @Value | ||
| @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE, onConstructor_ = @JsonCreator) | ||
| @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than changing this at RpcObjectData and in the specification itself, can we move the optimization to compact arrays to only affect the interaction between Java and JS because JS is slow at Object.keys() used for serializing in an object rather than a compact array?
* UUID generation fallback for Node version pre-14.17.0 (#6495) * UUID generation fallback for Node version pre-14.17.0 * Apply suggestions from code review * Use module-load-time selection for performance * Polish --------- Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Knut Wannheden <[email protected]> * Changing `AddDependencyVisitor` so it is able to broaden the scope of a direct dependency if needed (#6434) * Allowing `AddDependency` to broaden the scope of existing dependency, provided you're requesting an equal or higher version number. If requesting same scope but higher version number, the version number will be upgraded. * Dropping `import` scope validity in favour of `compile`, given `import` is only applicable for dependencies in `dependencyManagement` Co-authored-by: Tim te Beek <[email protected]> --------- Co-authored-by: Tim te Beek <[email protected]> * Add style parameter to OrderImports. (#6496) * Drop Lombok hint from RemoveUnusedImports class (#6500) * Drop Lombok hint from RemoveUnusedImports class Since we've supported Lombok for quite some time now. * Also update recipes.csv * In yaml `CopyValue`, invoke `UnfoldProperties` after `MergeYaml` (#6499) * unit test with poc for UnfoldProperties * use imperative CopyValue in unit test * Invoke UnfoldProperties after MergeYaml * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Slight polish --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]> * Allow adding comments to Maven plugins too Fixes #6502 * JavaScript: Make visitor base clases sync and add async alternative * Polish parser APIs * More async cleanups * JavaScript: Notify about parsed source files from `parseProject()` * Polish object property shorthand * Fix Prettier integration when calling it using sync API * Altering check for `AddDependency` to compare versions differently when direct vs indirect dependency. (#6505) * If transitive, actually just allow regardless of version, as per old behaviour. * Changing the parsing of the `relativePath` for `parent` in the `MavenPomDownloader` to prevent the situation where `/` was producing `/\pom.xml` on Windows rather than `\pom.xml` (#6506) * Claude/catalogue async apis u67 hy (#6507) * Convert package-manager and related APIs from async to sync - Convert runInstallInTempDir and runWorkspaceInstallInTempDir to use sync fs APIs (fs.mkdtempSync, fs.writeFileSync, fs.readFileSync, fs.rmSync) - Convert runInstallIfNeeded callback from async to sync - Convert updateNodeResolutionMarker to sync (was marked async with no awaits) - Convert createLockFileEditor to use sync JsonVisitor and TreeVisitor - Update add-dependency, upgrade-dependency-version, and upgrade-transitive-dependency-version recipes to use sync visitors - Convert Result.diff() to sync (createTwoFilesPatch is already sync) The package manager operations were unnecessarily async since the underlying process spawning (spawnSync) was already synchronous. Only the file I/O was async, which is negligible compared to the npm/yarn/pnpm install time. * Remove unnecessary async from IsSourceFile.preVisit() * Add async property to TreeVisitor and AsyncTreeVisitor Add a readonly `async` property to both visitor base classes: - TreeVisitor: async = false - AsyncTreeVisitor: async = true This allows runtime discrimination of sync vs async visitors via the RecipeVisitor union type. Useful for sync-to-sync recipe composition where a sync visitor wants to call another sync visitor without async overhead. * Lift async I/O out of visitors into editorWithData() Refactor package-manager recipes to do async I/O (npm install) in editorWithData() before returning the visitor, keeping visitors pure. Changes: - Add async runInstallInTempDirAsync() using spawn() and fs.promises - Add async runWorkspaceInstallInTempDirAsync() for workspace support - Refactor AddDependency, UpgradeDependencyVersion, and UpgradeTransitiveDependencyVersion to run package manager installs in editorWithData() before returning visitors - Remove unused runInstallIfNeeded() helper function - Visitors are now pure tree transformations with no I/O This provides a cleaner separation of concerns: - Async I/O happens in the recipe's async editor() method - Visitors are pure, synchronous tree transformations using pre-computed data * More sync visitors * Simplify receivers by extending visitors --------- Co-authored-by: Claude <[email protected]> * Bugfix * Add back runInstallIfNeeded() * Also parse `jrxml` as XML Fixes #6512 * Update description for onlyIfUsing option Clarified description for 'onlyIfUsing' option to specify its importance in multi-module projects. Fixes #5795 * Retain nested class imports in `ChangePackage` (#6515) Fixes #6513 * Add Python language support (#6508) * Compact array RpcObjectData only for JS * Less async test code --------- Co-authored-by: Benjamin Muschko <[email protected]> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Steve Elliott <[email protected]> Co-authored-by: Sam Snyder <[email protected]> Co-authored-by: David Grieve <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude <[email protected]> Co-authored-by: Jonathan Schnéider <[email protected]>
# Conflicts: # rewrite-java/src/main/java/org/openrewrite/java/OrderImports.java # rewrite-java/src/main/java/org/openrewrite/java/RemoveUnusedImports.java # rewrite-maven/src/main/java/org/openrewrite/maven/AddCommentToMavenDependency.java # rewrite-python/src/main/java/org/openrewrite/python/format/PythonSpaces.java # rewrite-python/src/test/java/org/openrewrite/python/style/AutodetectTest.java
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.
Optimizes RPC communication between Java and TypeScript for improved performance when processing large ASTs.
Wire format change
Before (JSON objects):
{ "state": "ADD", "valueType": "org.openrewrite.java.tree.J$Identifier", "value": null, "ref": 42 }After (compact arrays):
Key changes
RpcReceiveQueuefrom async to sync by pre-fetching all data batches upfront, eliminating async/await overhead[state, valueType, value, ref?, trace?]instead of JSON objects for RPC messages in both directionsreset()methods for cache clearing between benchmark iterations