Skip to content

Commit

Permalink
add a README.md for the shared script and .gitignore the file-sizes.j…
Browse files Browse the repository at this point in the history
…son file
  • Loading branch information
dim-daskalov committed Oct 8, 2024
1 parent 9623545 commit 0d25d1a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
3 changes: 2 additions & 1 deletion benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
build
file-sizes.json
3 changes: 2 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
node_modules
file-sizes.json
3 changes: 2 additions & 1 deletion packages/near-contract-standards/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
node_modules
file-sizes.json
71 changes: 71 additions & 0 deletions packages/shared-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# NEAR Shared Scripts

### calculate-file-sizes.js

It is used to track the file sizes contained in a given folder.

The script contains a few flags, which needs to be specified in order to work correctly.

There is a specific command added in every `package.json` for `benchmark`, `examples` and `tests`, which makes it easier to run the script.

Example:

In `examples` package, the command:

`pnpm calculate-file-sizes` will activate the script.

Message like this will pop up in the terminal:

`Please provide a directory path as an argument.`

Directory path will need to be added, for example `build` folder.

`pnpm calculate-file-sizes build`

Message like this will pop up in the terminal:

`Please specify either --before or --after flag.`

Flags:

`--before` This flag will trigger the process for calculating file sizes, before any optimization is made. It can ensure that the results before any changes made regarding that are saved into a `file-sizes.json` file, so they can be used after the optimization implementation is made. Do not remove this file if you want accurate results.

`--after` This flag should be used only after the optimization implementations are made in the project and it has been rebuild. This flag will trigger the process which will generate the results after the changes, compare it with the results from before optimization, generate an `WASM-FILE-SIZE-COMPARISON.md` file with a table including all the files and their data, and remove the `file-sizes.json` file.

The table generated will look something like this:

### WASM File Size Comparison Before and After Optimization

| File Name | Before Opt (KB) | After Opt (KB) | % Diff |
| :------------------------------------ | --------------: | -------------: | ------: |
| basic-updates-base.wasm | 500.53 | 477.35 | -4.63% |
| basic-updates-update.wasm | 562.14 | 498.71 | -11.27% |
| clean-state.wasm | 496.45 | 473.48 | -4.62% |
| counter-lowlevel.wasm | 472.62 | 468.67 | -0.84% |
| counter-ts.wasm | 496.66 | 473.56 | -4.66% |
| counter.wasm | 496.56 | 473.51 | -4.64% |
| cross-contract-call-loop.wasm | 504.86 | 480.77 | -4.77% |
| cross-contract-call-ts.wasm | 498.54 | 475.04 | -4.71% |
| cross-contract-call.wasm | 498.51 | 475.01 | -4.71% |
| fungible-token-helper.wasm | 495.88 | 472.92 | -4.63% |
| fungible-token-lockable.wasm | 505.26 | 481.73 | -4.66% |
| fungible-token.wasm | 505.12 | 481.39 | -4.69% |
| my-ft.wasm | 520.98 | 495.55 | -4.89% |
| my-nft.wasm | 534.88 | 507.94 | -5.04% |
| nested-collections.wasm | 504.90 | 481.18 | -4.71% |
| nft-approval-receiver.wasm | 504.91 | 480.82 | -4.76% |
| nft-receiver.wasm | 505.10 | 481.05 | -4.76% |
| non-fungible-token-receiver.wasm | 496.51 | 473.51 | -4.63% |
| non-fungible-token.wasm | 503.30 | 479.39 | -4.76% |
| parking-lot.wasm | 500.11 | 476.87 | -4.65% |
| programmatic-update-after.wasm | 496.49 | 473.41 | -4.65% |
| programmatic-update-before.wasm | 496.47 | 473.38 | -4.65% |
| state-migration-new.wasm | 501.13 | 477.72 | -4.67% |
| state-migration-original.wasm | 499.98 | 476.68 | -4.65% |
| status-deserialize-class.wasm | 522.52 | 498.15 | -4.66% |
| status-message-borsh.wasm | 506.13 | 482.19 | -4.73% |
| status-message-collections.wasm | 505.38 | 481.67 | -4.70% |
| status-message-deserialize-err.wasm | 496.05 | 473.03 | -4.64% |
| status-message-migrate-add-field.wasm | 498.11 | 475.02 | -4.64% |
| status-message-serialize-err.wasm | 496.05 | 473.03 | -4.64% |
| status-message.wasm | 496.19 | 473.16 | -4.65% |
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
build
file-sizes.json

0 comments on commit 0d25d1a

Please sign in to comment.