From 8d834e2eabdb7b846f451b39cceaf3383eb121b5 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 19 Apr 2025 18:26:08 +0200 Subject: [PATCH] Pack the models.Commit struct a little tighter Change the base type of some of our enums from int to uint8, and reorder fields for better packing. This reduces the size of models.Commit from 152 to 132 bytes on my machine. This doesn't improve overall memory usage significantly, but why not save a little bit of memory if it's easy. --- pkg/commands/models/commit.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 638153ed8..37a9be28d 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -11,7 +11,7 @@ import ( // Special commit hash for empty tree object const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" -type CommitStatus int +type CommitStatus uint8 const ( StatusNone CommitStatus = iota @@ -30,7 +30,7 @@ const ( ActionNone todo.TodoCommand = 0 ) -type Divergence int +type Divergence uint8 // For a divergence log (left/right comparison of two refs) this is set to // either DivergenceLeft or DivergenceRight for each commit; for normal @@ -45,17 +45,18 @@ const ( type Commit struct { hash *string Name string - Status CommitStatus - Action todo.TodoCommand Tags []string ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2' AuthorName string // something like 'Jesse Duffield' AuthorEmail string // something like 'jessedduffield@gmail.com' UnixTimestamp int64 - Divergence Divergence // set to DivergenceNone unless we are showing the divergence view // Hashes of parent commits (will be multiple if it's a merge commit) parents []*string + + Status CommitStatus + Action todo.TodoCommand + Divergence Divergence // set to DivergenceNone unless we are showing the divergence view } type NewCommitOpts struct {