cosmos-sdk/orm
Aaron Craelius 5cbdad3584
perf(orm): add benchmarks (#11525)
## Description

This PR adds benchmarks for inserting, updating, deleting and getting a simple entity compared with handwritten versions of this code.

Two simple optimizations were found with these benchmarks and included in this PR:
* correctly compute buffer size in `KeyCodec.EncodeKey` to avoid growing the buffer
* use `value.String()` instead of `value.Interface().(string)` as the latter causes an additional allocation

Other potential places for optimization can be seen by running CPU and memory profiles. In particular, update is significantly slower because the ORM assumes the existing value always needs to be decoded to keep indexes up-to-date which is not the case in this simple example. In the future, the ORM code generator could potentially generate more code up to the point of essentially mimicking the manual versions if performance tradeoffs become the bottleneck.

As a follow-up, we should do benchmarks using an IAVL tree as the backing store to see if the ORM overhead is significant in a more real-world scenario.



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-04-08 13:22:44 +00:00
..
cmd/protoc-gen-go-cosmos-orm feat(orm): codegen (#11033) 2022-01-28 18:43:24 +00:00
encoding perf(orm): add benchmarks (#11525) 2022-04-08 13:22:44 +00:00
features/table feat(orm): gRPC codes for save errors (#11386) 2022-03-17 18:57:55 +00:00
internal perf(orm): add benchmarks (#11525) 2022-04-08 13:22:44 +00:00
model perf(orm): add benchmarks (#11525) 2022-04-08 13:22:44 +00:00
testing refactor(orm)!: refactor hooks into validate and write hooks (#11185) 2022-02-25 14:54:44 +01:00
types fix(orm): add additional checks on invalid tables (#11387) 2022-04-05 19:48:58 +00:00
Makefile feat(orm): codegen (#11033) 2022-01-28 18:43:24 +00:00
go.mod build(deps): Bump github.com/cosmos/cosmos-sdk/api from 0.1.0-alpha5 to 0.1.0 in /orm (#11520) 2022-04-04 06:25:36 +00:00
go.sum build(deps): Bump github.com/cosmos/cosmos-sdk/api from 0.1.0-alpha5 to 0.1.0 in /orm (#11520) 2022-04-04 06:25:36 +00:00