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

feat(p/int256): Optimize int256 with two's complement implementation #2846

Merged
merged 19 commits into from
Nov 21, 2024

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Sep 25, 2024

Description

This PR optimizes the implementation of int256 type. Key changes include:

  • Changed from storing sign and value separately in the Int256 struct to an implementation using two's complement method.
  • This reduces unnecessary operations and improves overall performance.

Performance Result

  • Basic arithmetic operations (addition, subtraction, etc.): About 3x performance improvement (based on Go benchmarks, may differ slightly in gno)
  • Division operations: Up to 5x performance decrease compared to the previous implementation (can be improved by directly manipulating array fields, but not applied to avoid duplication with p/demo/uint256)

Additional improvements:

  • Increased test coverage to 95%.

This change is expected to improve performance for most int256 operations. However, please note the performance degradation in division operations.

See Also

#2750 (review)

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Sep 25, 2024
Copy link

codecov bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@notJoon notJoon marked this pull request as ready for review September 26, 2024 09:19
@notJoon notJoon requested review from a team as code owners September 26, 2024 09:19
@notJoon notJoon requested review from gfanton and petar-dambovaliev and removed request for a team September 26, 2024 09:19
@Kouteki Kouteki added review/triage-pending PRs opened by external contributors that are waiting for the 1st review and removed review/triage-pending PRs opened by external contributors that are waiting for the 1st review labels Oct 3, 2024
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

great stuff

examples/gno.land/p/demo/int256/arithmetic.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/int256/bitwise_test.gno Outdated Show resolved Hide resolved
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

A few more comments, apologies

examples/gno.land/p/demo/int256/arithmetic_test.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/int256/conversion.gno Outdated Show resolved Hide resolved
@Kouteki Kouteki requested review from ltzmaxwell and removed request for a team and gfanton November 18, 2024 06:44
Copy link
Contributor

@ltzmaxwell ltzmaxwell left a comment

Choose a reason for hiding this comment

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

partial, will carry on later

examples/gno.land/p/demo/int256/arithmetic.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/int256/int256.gno Show resolved Hide resolved
@Kouteki Kouteki added the in focus Core team is prioritizing this work label Nov 21, 2024
@ltzmaxwell ltzmaxwell merged commit 7718bc3 into gnolang:master Nov 21, 2024
101 checks passed
@notJoon notJoon deleted the int256-v2 branch November 21, 2024 10:07
@Kouteki Kouteki removed the in focus Core team is prioritizing this work label Nov 29, 2024
@gnolang gnolang deleted a comment from Gno2D2 Dec 2, 2024
r3v4s pushed a commit to gnoswap-labs/gno that referenced this pull request Dec 10, 2024
gnolang#2846)

# Description

This PR optimizes the implementation of `int256` type. Key changes
include:

- Changed from storing sign and value separately in the Int256 struct to
an implementation using two's complement method.
- This reduces unnecessary operations and improves overall performance.

## Performance Result

- Basic arithmetic operations (addition, subtraction, etc.): About 3x
performance improvement (based on Go benchmarks, may differ slightly in
gno)
- Division operations: Up to 5x performance decrease compared to the
previous implementation (can be improved by directly manipulating array
fields, but not applied to avoid duplication with p/demo/uint256)

## Additional improvements:
- Increased test coverage to 95%.

**This change is expected to improve performance for most int256
operations. However, please note the performance degradation in division
operations.**

## See Also

gnolang#2750 (review)

<details><summary>Contributors' checklist...</summary>

- [X] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Morgan <[email protected]>
albttx pushed a commit that referenced this pull request Jan 10, 2025
#2846)

# Description

This PR optimizes the implementation of `int256` type. Key changes
include:

- Changed from storing sign and value separately in the Int256 struct to
an implementation using two's complement method.
- This reduces unnecessary operations and improves overall performance.

## Performance Result

- Basic arithmetic operations (addition, subtraction, etc.): About 3x
performance improvement (based on Go benchmarks, may differ slightly in
gno)
- Division operations: Up to 5x performance decrease compared to the
previous implementation (can be improved by directly manipulating array
fields, but not applied to avoid duplication with p/demo/uint256)

## Additional improvements:
- Increased test coverage to 95%.

**This change is expected to improve performance for most int256
operations. However, please note the performance degradation in division
operations.**

## See Also

#2750 (review)

<details><summary>Contributors' checklist...</summary>

- [X] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Morgan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants