# Optimize Writer.writeLeb128 · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ceba9572ef5fc3a4c7e2e3f315d05842d2422d0c)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ceba9572ef5fc3a4c7e2e3f315d05842d2422d0c

Requested commit: ceba9572ef5fc3a4c7e2e3f315d05842d2422d0c

Commit: ceba9572ef5fc3a4c7e2e3f315d05842d2422d0c

Tree: 58f2fc73dbe862b1457f1acd598535423f5ab046

Author: Nico Elbers

Committer: Nico Elbers

## Message

```
Optimize Writer.writeLeb128

Rewrite `writeLeb128` to no longer use `writeMultipleOf7Leb128` and instead:
 * Make use of byte aligned ints
 * Special case small numbers (fitting inside 7 bits)

Amongst u8, u16, u32 and u64 performance gains are between ~1.5x and ~2x
Amongst i8, i16, i32 ane i64 perfromance gains are between ~2x and >4x

Additinally add test coverage for written encodings

Microbenchmark: https://zigbin.io/7ed5fe

```

## Parents

- [854774d468b0a439def7eef73c544ac8d64f1b62](https://git.cafe/gitcafe/zig/commit/854774d468b0a439def7eef73c544ac8d64f1b62?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ceba9572ef5fc3a4c7e2e3f315d05842d2422d0c?format=markdown)
