-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: compiler outputs might exceed the max buffer size #6411
Open
galargh
wants to merge
3
commits into
v-next
Choose a base branch
from
json-stream
base: v-next
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 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
🦋 Changeset detectedLatest commit: 27764db The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
hardhatTotal size of the bundle: List of dependencies (sorted by size)
|
This was referenced Feb 26, 2025
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.
Resolves: #6336
Resolves: #6328
In this PR, I start using streams when handling the solc compiler outputs to support the compilation of very large codebases where the compilation outputs might exceed the maximum buffer size/string length.
Changes to the build system and cache
I added two new file system access functions:
readJsonFileAsStream
: opens the file as a stream, passes it to the streaming JSON parser, picks the full parsed object from the JSON values streamwriteJsonFileAsStream
: parses the JSON object as a stream of tokens, writes it to the fileThese functions allow us to avoid storing the full compiler output as a string, which can exceed the maximum string length at times.
To implement these functions, I added two new dependencies:
These functions are used when interacting with compiler output objects, in the cache and when emitting the build info output.
Changes to the compiler
Previously, the compiler would execute the underlying solc compiler using the
execFile
function. With that function, we would end up waiting for the entire output to be returned to us as a string. Unfortunately, for very large compiler outputs, the resulting output would exceed the max buffer size and if we increased the buffer size further, we would eventually hit the maximum string length limit.I removed the usage of
execFile
from the compiler and replaced it withspawn
, where we pipe the output to a temporary file which we later read using the newly addedreadJsonFileAsStream
function. This allows us to avoid creating a string of the compiler output.Follow-ups
Deduplicate compiler output file creation
At the moment, we create a file with compiler output three times, in the Compiler, when saving the output to the cache, and when emitting the build info output. We should consider creating it only once and then copying/moving it when needed. This will require changing the build info output format which currently has some extra information apart from the compiler output.
Testing
I rerun the solidity testing testing suite using this branch which cleared all the 143s and max buffer size exceeded errors. My hypothesis on why the 143 were cleared as well is that in these cases, we weren't exceeding the max buffer size, but we were running very near it, which caused the memory pressure.
https://github.com/galargh/solidity-testing-testing/actions/runs/13542801435