forked from near/near-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[DRAFT] - [perf] - wasm optimisations #6
Open
pivanov
wants to merge
8
commits into
develop
Choose a base branch
from
wasm-file-size
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3047a36
[perf] - wasm optimisations
d87245f
add the shared-scripts package, include the generate-report and calcu…
dim-daskalov 10b3c7a
add a README.md for the shared script and .gitignore the file-sizes.j…
dim-daskalov 2274270
address Valeri's comments, move the shared-scripts to devDependencies…
dim-daskalov 098bacf
remove the redundant shared-scripts from package.json files
dim-daskalov 32d3558
optimize the redundant code and add docstrings on the new functions a…
dim-daskalov dab3d33
address Pavkata's comments, added error handling for file operations
dim-daskalov de6034d
address Pavkata's comments, remove redundand code, optimize the forma…
dim-daskalov 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
vendor | ||
.idea | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build | ||
build | ||
file-sizes.json |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const resultsFilePath = path.resolve("temp-all-test-results.json"); | ||
|
||
/** | ||
* Reads existing test results from a JSON file if it exists. | ||
* | ||
* This function checks if the file specified by `resultsFilePath` exists. | ||
* If the file is found, it reads the file's content and parses it as JSON. | ||
* If the file does not exist, it returns an empty object. | ||
* | ||
* @returns {Object} The parsed JSON object from the file, or an empty object if the file does not exist. | ||
*/ | ||
function readExistingResults() { | ||
if (fs.existsSync(resultsFilePath)) { | ||
try { | ||
const fileContent = fs.readFileSync(resultsFilePath, "utf-8"); | ||
return JSON.parse(fileContent); | ||
} catch (error) { | ||
console.error("Failed to read or parse results file:", error); | ||
return {}; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
/** | ||
* Function to add test results to the report if the GENERATE_REPORT environment variable is set to "true" | ||
* @param {string} testName - The name of the test. | ||
* @param {Object} result - The test result object. | ||
*/ | ||
export function addTestResults(testName, result) { | ||
// Check if we need to generate a report | ||
if (process.env.GENERATE_REPORT === "true") { | ||
// Create a temporary object for the new test results | ||
const tempResults = { | ||
[testName]: result, | ||
}; | ||
|
||
// Read existing results from the file | ||
const existingResults = readExistingResults(); | ||
|
||
// Combine existing results with new test results | ||
const combinedResults = { | ||
...existingResults, | ||
...tempResults, | ||
}; | ||
|
||
try { | ||
// Write the combined results to the file | ||
fs.writeFileSync( | ||
resultsFilePath, | ||
JSON.stringify(combinedResults, null, 2) | ||
); | ||
} catch (error) { | ||
console.error("Failed to write results to file:", error); | ||
} | ||
} | ||
} |
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
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
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
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
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.
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.
Lack of error handling:
If there is an error while reading or writing the file, it can cause the program to crash without any clear indication. You should wrap file operations in try-catch blocks to gracefully handle potential file system errors.
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.
Yea, you're right. Thanks for pointing that out.