From 2be5051b19a397eff187b2f458b0c8aeece4e83b Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 24 Feb 2024 14:42:43 +0100 Subject: [PATCH] Reorder the fields of the Entry struct to save some memory Given that there is always a ton of `Entry` floating around, reordering its field to take less space is a quick/simple way to reduce miniflux' memory consumption. I kept the `ID` field as the first member, as I think it's the most important one, and moving it somewhere else would drown it in other fields. Anyway, this still provides a reduction of 32 bytes per Entry: ```console $ fieldalignment ./client/model.go 2>&1 | grep 203 ~/v2/client/model.go:203:12: struct with 280 pointer bytes could be 240 $ fieldalignment ./client/model.go 2>&1 | grep 203 ~/v2/client/model.go:203:12: struct with 248 pointer bytes could be 240 $ ``` The same optimisation pass could be applied to other structs, but since they aren't present in obviously great numbers during miniflux' life cycle, it would likely require some profiling to see if it's worth doing it. --- client/model.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client/model.go b/client/model.go index 4808b31d..b404915f 100644 --- a/client/model.go +++ b/client/model.go @@ -202,24 +202,24 @@ type Feeds []*Feed // Entry represents a subscription item in the system. type Entry struct { ID int64 `json:"id"` - UserID int64 `json:"user_id"` - FeedID int64 `json:"feed_id"` - Status string `json:"status"` + Date time.Time `json:"published_at"` + ChangedAt time.Time `json:"changed_at"` + CreatedAt time.Time `json:"created_at"` + Feed *Feed `json:"feed,omitempty"` Hash string `json:"hash"` - Title string `json:"title"` URL string `json:"url"` CommentsURL string `json:"comments_url"` - Date time.Time `json:"published_at"` - CreatedAt time.Time `json:"created_at"` - ChangedAt time.Time `json:"changed_at"` + Title string `json:"title"` + Status string `json:"status"` Content string `json:"content"` Author string `json:"author"` ShareCode string `json:"share_code"` - Starred bool `json:"starred"` - ReadingTime int `json:"reading_time"` Enclosures Enclosures `json:"enclosures,omitempty"` - Feed *Feed `json:"feed,omitempty"` Tags []string `json:"tags"` + ReadingTime int `json:"reading_time"` + UserID int64 `json:"user_id"` + FeedID int64 `json:"feed_id"` + Starred bool `json:"starred"` } // EntryModificationRequest represents a request to modify an entry.