Skip to content
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

lang: boxed the inner Enums of anchor_lang::error to fit within 128 bytes #2600

Merged
merged 9 commits into from
Aug 30, 2023
Merged

Conversation

wjthieme
Copy link
Contributor

@wjthieme wjthieme commented Aug 12, 2023

Fixes Clippy error result_large_err on anchor_lang::error:Error.

Have not fully looked at implications further than building the anchor_lang crate and using it to build an anchor program.

Fixes #2599

@vercel
Copy link

vercel bot commented Aug 12, 2023

@wjthieme is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@wjthieme wjthieme changed the title Boxed the inner Enums of anchor_lang::error to fit within 128 bytes lang: boxed the inner Enums of anchor_lang::error to fit within 128 bytes Aug 12, 2023
@acheroncrypto
Copy link
Collaborator

We currently use ignore this lint:

large-error-threshold = 1_000_000

Big part of this size is coming from ComparedValues enum(because of the 2 pubkeys):

anchor/lang/src/error.rs

Lines 413 to 416 in b5cf67f

pub enum ComparedValues {
Values((String, String)),
Pubkeys((Pubkey, Pubkey)),
}

I wonder why this was ignored rather than solved, this will also improve the performance(compute units, binary size, stack usage).

@wjthieme
Copy link
Contributor Author

Same. Think this is ready for a review @acheroncrypto

@acheroncrypto
Copy link
Collaborator

Bench test is failing due to the changes not being updated. Planning to add stack memory benchmarks next week so it would be better to merge this after the memory benchmarks to document changes.

| bench | 1,153,736 | - |
| Program | Binary Size | +/- |
| ------- | ----------- | ---------------------- |
| bench | 1,075,688 | 🟢 **-78,048 (6.76%)** |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.76% decrease in program binary size is pretty wild with this change

@acheroncrypto acheroncrypto merged commit dcf5928 into coral-xyz:master Aug 30, 2023
45 of 46 checks passed
Aursen added a commit to Aursen/anchor that referenced this pull request Sep 11, 2023
commit cec9946
Author: Jesserc <[email protected]>
Date:   Sun Sep 10 20:32:34 2023 +0100

    docs: Fix typo and grammar in error documentation

commit 4955a92
Author: acheron <[email protected]>
Date:   Fri Sep 8 10:01:51 2023 +0200

    Add byte slice(`&[u8]`) support for `idl-build` (coral-xyz#2622)

commit a1e4453
Author: acheron <[email protected]>
Date:   Tue Sep 5 17:30:53 2023 +0200

    cli: Make conflicting account names a compile-time error (coral-xyz#2621)

commit b9fa898
Author: acheron <[email protected]>
Date:   Fri Sep 1 22:42:06 2023 +0200

    cli: Fix `anchor account` command panicking outside of workspace (coral-xyz#2620)

commit dcf5928
Author: Will <[email protected]>
Date:   Wed Aug 30 19:28:51 2023 +0200

    lang: `Box` the inner enums of `anchor_lang::error::Error` (coral-xyz#2600)

    Co-authored-by: acheron <[email protected]>

commit 115679e
Author: acheron <[email protected]>
Date:   Mon Aug 28 14:13:12 2023 +0200

    bench: Add benchmarking for stack memory usage (coral-xyz#2617)

commit a5e4c02
Author: acheron <[email protected]>
Date:   Sun Aug 27 10:21:17 2023 +0200

    ts: Bump packages to `0.28.1-beta.2` (coral-xyz#2616)

commit a7205af
Author: Will <[email protected]>
Date:   Wed Aug 23 22:10:08 2023 +0200

    lang: `associated_token` constraints don't work when setting `token_program` (coral-xyz#2603)

    Co-authored-by: acheron <[email protected]>

commit 6f9f7d9
Author: acheron <[email protected]>
Date:   Sat Aug 19 13:09:09 2023 +0200

    tests: Move IDL related tests in `misc` to `idl` (coral-xyz#2606)

commit 6eacad4
Author: acheron <[email protected]>
Date:   Tue Aug 15 23:58:17 2023 +0200

    cli: Add program template with multiple files (coral-xyz#2602)

commit 454f1dd
Author: acheron <[email protected]>
Date:   Sun Aug 13 16:50:28 2023 +0200

    ts: Add support for unnamed(tuple) enum in accounts (coral-xyz#2601)

commit b5cf67f
Author: Jimii <[email protected]>
Date:   Sat Aug 12 23:02:37 2023 +0300

    spl: Add `TokenRecordAccount` for pNFTs (coral-xyz#2597)

commit 58428f8
Author: Proph3t <[email protected]>
Date:   Fri Aug 11 19:48:28 2023 +0000

    Add `setup_tests.sh` for setting up your local machine for tests (coral-xyz#2594)

commit 4cf447a
Author: acheron <[email protected]>
Date:   Tue Aug 8 22:03:31 2023 +0200

    bench: Add benchmarking for program binary size (coral-xyz#2591)

commit abfdc4e
Author: acheron <[email protected]>
Date:   Sat Aug 5 23:47:06 2023 +0200

    chore: Remove duplicate dependency and and alphabetize features (coral-xyz#2590)

commit 2af9cc6
Author: acheron <[email protected]>
Date:   Wed Aug 2 23:01:05 2023 +0200

    cli: Improve converting non-conflicting paths to names in IDL (coral-xyz#2588)

commit be8764b
Author: Proph3t <[email protected]>
Date:   Tue Aug 1 20:23:48 2023 +0000

    Fix typo in account.rs docs (coral-xyz#2587)

commit b7b8736
Author: acheron <[email protected]>
Date:   Mon Jul 31 23:41:12 2023 +0200

    spl: Export `mpl-token-metadata` crate (coral-xyz#2583)

commit cad868a
Author: acheron <[email protected]>
Date:   Sat Jul 29 23:49:17 2023 +0200

    Make the new IDL features explicit (coral-xyz#2582)

commit 8f30f00
Author: acheron <[email protected]>
Date:   Thu Jul 27 23:29:26 2023 +0200

    tests: Improve IDL comparison tests (coral-xyz#2581)

commit df3e959
Author: Pierre <[email protected]>
Date:   Thu Jul 27 07:56:12 2023 +1000

    chore: Use @noble/hashes/sha256 rather than obscure package (coral-xyz#2580)

commit 5eb678a
Author: acheron <[email protected]>
Date:   Tue Jul 25 23:52:26 2023 +0200

    ts: Lazy load workspace programs and improve program name accessor (coral-xyz#2579)

commit 4604fbe
Author: acheron <[email protected]>
Date:   Sat Jul 22 16:39:05 2023 +0200

    cli: Automatically decide IDL generation method (coral-xyz#2578)

commit c548c85
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Sat Jul 22 12:43:56 2023 +0200

    chore: Remove unused crates (coral-xyz#2577)

commit 2bb3237
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Fri Jul 21 11:04:52 2023 +0200

    chore: Fix clippy lints (coral-xyz#2576)

commit 10eb698
Author: dromaz <[email protected]>
Date:   Thu Jul 20 23:58:13 2023 +0200

    avm: Add support for the `.anchorversion` file (coral-xyz#2553)

    Co-authored-by: acheron <[email protected]>

commit 8309bb3
Author: acheron <[email protected]>
Date:   Wed Jul 19 18:28:38 2023 +0200

    cli: Fix `anchor build --no-docs` (coral-xyz#2575)

commit c306463
Author: acheron <[email protected]>
Date:   Mon Jul 17 22:47:55 2023 +0200

    tests: Refactor IDL tests (coral-xyz#2573)

commit cf057ac
Author: acheron <[email protected]>
Date:   Sun Jul 16 17:08:25 2023 +0200

    client: Fix compilation with Solana `1.14` (coral-xyz#2572)

commit 4e5280b
Author: acheron <[email protected]>
Date:   Fri Jul 14 23:17:23 2023 +0200

    cli: Fix workspace inheritence (coral-xyz#2570)

commit cfc6d29
Author: Lucas Steuernagel <[email protected]>
Date:   Fri Jul 14 16:29:16 2023 -0300

    cli: Bump `solang-parser` version (coral-xyz#2569)

commit 472279d
Author: acheron <[email protected]>
Date:   Thu Jul 13 22:06:12 2023 +0200

    cli: Add `--out` and `--out-ts` arguments for `idl build` command (coral-xyz#2566)

commit b7e91d4
Author: acheron <[email protected]>
Date:   Tue Jul 11 19:05:14 2023 +0200

    Remove IDL `path` field (coral-xyz#2564)

commit 6ef6b79
Author: Krešimir Klas <[email protected]>
Date:   Sat Jul 8 19:59:30 2023 +0200

    IDL generation through compilation (coral-xyz#2011)

    Co-authored-by: acheron <[email protected]>

commit 0225b7c
Author: Noah Prince <[email protected]>
Date:   Fri Jul 7 14:30:38 2023 -0700

    lang: Allow polymorphic CPI calls matching an interface (coral-xyz#2559)

commit 9ff7dfc
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Wed Jul 5 10:05:37 2023 +0200

    lang: Support for `const` in the `InitSpace` macro (coral-xyz#2555)

commit 401d526
Author: chalda <[email protected]>
Date:   Mon Jul 3 22:56:58 2023 +0200

    client: Add `DynSigner` (coral-xyz#2550)

commit e55cd3e
Author: acheron <[email protected]>
Date:   Sat Jul 1 22:59:36 2023 +0200

    lang: Add `Lamports` trait (coral-xyz#2552)

commit 5624bfe
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Thu Jun 29 13:35:38 2023 +0200

    lang: Fix typo in the doc (coral-xyz#2551)

commit 29b8a72
Author: acheron <[email protected]>
Date:   Tue Jun 27 20:03:51 2023 +0200

    bench: Show change amount and add change note (coral-xyz#2549)

commit 8bdc1b1
Author: Han Yang <[email protected]>
Date:   Tue Jun 27 01:04:30 2023 +0800

    spl: Only allow spl-token version above 1.1 (coral-xyz#2546)
Aursen added a commit to Aursen/anchor that referenced this pull request Sep 11, 2023
commit cec9946
Author: Jesserc <[email protected]>
Date:   Sun Sep 10 20:32:34 2023 +0100

    docs: Fix typo and grammar in error documentation

commit 4955a92
Author: acheron <[email protected]>
Date:   Fri Sep 8 10:01:51 2023 +0200

    Add byte slice(`&[u8]`) support for `idl-build` (coral-xyz#2622)

commit a1e4453
Author: acheron <[email protected]>
Date:   Tue Sep 5 17:30:53 2023 +0200

    cli: Make conflicting account names a compile-time error (coral-xyz#2621)

commit b9fa898
Author: acheron <[email protected]>
Date:   Fri Sep 1 22:42:06 2023 +0200

    cli: Fix `anchor account` command panicking outside of workspace (coral-xyz#2620)

commit dcf5928
Author: Will <[email protected]>
Date:   Wed Aug 30 19:28:51 2023 +0200

    lang: `Box` the inner enums of `anchor_lang::error::Error` (coral-xyz#2600)

    Co-authored-by: acheron <[email protected]>

commit 115679e
Author: acheron <[email protected]>
Date:   Mon Aug 28 14:13:12 2023 +0200

    bench: Add benchmarking for stack memory usage (coral-xyz#2617)

commit a5e4c02
Author: acheron <[email protected]>
Date:   Sun Aug 27 10:21:17 2023 +0200

    ts: Bump packages to `0.28.1-beta.2` (coral-xyz#2616)

commit a7205af
Author: Will <[email protected]>
Date:   Wed Aug 23 22:10:08 2023 +0200

    lang: `associated_token` constraints don't work when setting `token_program` (coral-xyz#2603)

    Co-authored-by: acheron <[email protected]>

commit 6f9f7d9
Author: acheron <[email protected]>
Date:   Sat Aug 19 13:09:09 2023 +0200

    tests: Move IDL related tests in `misc` to `idl` (coral-xyz#2606)

commit 6eacad4
Author: acheron <[email protected]>
Date:   Tue Aug 15 23:58:17 2023 +0200

    cli: Add program template with multiple files (coral-xyz#2602)

commit 454f1dd
Author: acheron <[email protected]>
Date:   Sun Aug 13 16:50:28 2023 +0200

    ts: Add support for unnamed(tuple) enum in accounts (coral-xyz#2601)

commit b5cf67f
Author: Jimii <[email protected]>
Date:   Sat Aug 12 23:02:37 2023 +0300

    spl: Add `TokenRecordAccount` for pNFTs (coral-xyz#2597)

commit 58428f8
Author: Proph3t <[email protected]>
Date:   Fri Aug 11 19:48:28 2023 +0000

    Add `setup_tests.sh` for setting up your local machine for tests (coral-xyz#2594)

commit 4cf447a
Author: acheron <[email protected]>
Date:   Tue Aug 8 22:03:31 2023 +0200

    bench: Add benchmarking for program binary size (coral-xyz#2591)

commit abfdc4e
Author: acheron <[email protected]>
Date:   Sat Aug 5 23:47:06 2023 +0200

    chore: Remove duplicate dependency and and alphabetize features (coral-xyz#2590)

commit 2af9cc6
Author: acheron <[email protected]>
Date:   Wed Aug 2 23:01:05 2023 +0200

    cli: Improve converting non-conflicting paths to names in IDL (coral-xyz#2588)

commit be8764b
Author: Proph3t <[email protected]>
Date:   Tue Aug 1 20:23:48 2023 +0000

    Fix typo in account.rs docs (coral-xyz#2587)

commit b7b8736
Author: acheron <[email protected]>
Date:   Mon Jul 31 23:41:12 2023 +0200

    spl: Export `mpl-token-metadata` crate (coral-xyz#2583)

commit cad868a
Author: acheron <[email protected]>
Date:   Sat Jul 29 23:49:17 2023 +0200

    Make the new IDL features explicit (coral-xyz#2582)

commit 8f30f00
Author: acheron <[email protected]>
Date:   Thu Jul 27 23:29:26 2023 +0200

    tests: Improve IDL comparison tests (coral-xyz#2581)

commit df3e959
Author: Pierre <[email protected]>
Date:   Thu Jul 27 07:56:12 2023 +1000

    chore: Use @noble/hashes/sha256 rather than obscure package (coral-xyz#2580)

commit 5eb678a
Author: acheron <[email protected]>
Date:   Tue Jul 25 23:52:26 2023 +0200

    ts: Lazy load workspace programs and improve program name accessor (coral-xyz#2579)

commit 4604fbe
Author: acheron <[email protected]>
Date:   Sat Jul 22 16:39:05 2023 +0200

    cli: Automatically decide IDL generation method (coral-xyz#2578)

commit c548c85
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Sat Jul 22 12:43:56 2023 +0200

    chore: Remove unused crates (coral-xyz#2577)

commit 2bb3237
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Fri Jul 21 11:04:52 2023 +0200

    chore: Fix clippy lints (coral-xyz#2576)

commit 10eb698
Author: dromaz <[email protected]>
Date:   Thu Jul 20 23:58:13 2023 +0200

    avm: Add support for the `.anchorversion` file (coral-xyz#2553)

    Co-authored-by: acheron <[email protected]>

commit 8309bb3
Author: acheron <[email protected]>
Date:   Wed Jul 19 18:28:38 2023 +0200

    cli: Fix `anchor build --no-docs` (coral-xyz#2575)

commit c306463
Author: acheron <[email protected]>
Date:   Mon Jul 17 22:47:55 2023 +0200

    tests: Refactor IDL tests (coral-xyz#2573)

commit cf057ac
Author: acheron <[email protected]>
Date:   Sun Jul 16 17:08:25 2023 +0200

    client: Fix compilation with Solana `1.14` (coral-xyz#2572)

commit 4e5280b
Author: acheron <[email protected]>
Date:   Fri Jul 14 23:17:23 2023 +0200

    cli: Fix workspace inheritence (coral-xyz#2570)

commit cfc6d29
Author: Lucas Steuernagel <[email protected]>
Date:   Fri Jul 14 16:29:16 2023 -0300

    cli: Bump `solang-parser` version (coral-xyz#2569)

commit 472279d
Author: acheron <[email protected]>
Date:   Thu Jul 13 22:06:12 2023 +0200

    cli: Add `--out` and `--out-ts` arguments for `idl build` command (coral-xyz#2566)

commit b7e91d4
Author: acheron <[email protected]>
Date:   Tue Jul 11 19:05:14 2023 +0200

    Remove IDL `path` field (coral-xyz#2564)

commit 6ef6b79
Author: Krešimir Klas <[email protected]>
Date:   Sat Jul 8 19:59:30 2023 +0200

    IDL generation through compilation (coral-xyz#2011)

    Co-authored-by: acheron <[email protected]>

commit 0225b7c
Author: Noah Prince <[email protected]>
Date:   Fri Jul 7 14:30:38 2023 -0700

    lang: Allow polymorphic CPI calls matching an interface (coral-xyz#2559)

commit 9ff7dfc
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Wed Jul 5 10:05:37 2023 +0200

    lang: Support for `const` in the `InitSpace` macro (coral-xyz#2555)

commit 401d526
Author: chalda <[email protected]>
Date:   Mon Jul 3 22:56:58 2023 +0200

    client: Add `DynSigner` (coral-xyz#2550)

commit e55cd3e
Author: acheron <[email protected]>
Date:   Sat Jul 1 22:59:36 2023 +0200

    lang: Add `Lamports` trait (coral-xyz#2552)

commit 5624bfe
Author: Jean Marchand (Exotic Markets) <[email protected]>
Date:   Thu Jun 29 13:35:38 2023 +0200

    lang: Fix typo in the doc (coral-xyz#2551)

commit 29b8a72
Author: acheron <[email protected]>
Date:   Tue Jun 27 20:03:51 2023 +0200

    bench: Show change amount and add change note (coral-xyz#2549)

commit 8bdc1b1
Author: Han Yang <[email protected]>
Date:   Tue Jun 27 01:04:30 2023 +0800

    spl: Only allow spl-token version above 1.1 (coral-xyz#2546)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lang: the Err-variant returned from this function is very large
2 participants