Skip to content

Commit

Permalink
feat(p/int256): Optimize int256 with two's complement implementation (
Browse files Browse the repository at this point in the history
#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]>
  • Loading branch information
notJoon and thehowl authored Nov 21, 2024
1 parent 889082f commit 7718bc3
Show file tree
Hide file tree
Showing 21 changed files with 1,247 additions and 985 deletions.
21 changes: 0 additions & 21 deletions examples/gno.land/p/demo/int256/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions examples/gno.land/p/demo/int256/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions examples/gno.land/p/demo/int256/absolute.gno

This file was deleted.

105 changes: 0 additions & 105 deletions examples/gno.land/p/demo/int256/absolute_test.gno

This file was deleted.

Loading

0 comments on commit 7718bc3

Please sign in to comment.