align structs for better memory layout

This commit is contained in:
Laptop
2025-08-31 00:43:25 +03:00
parent e0bfcaadba
commit 0474290010
8 changed files with 49 additions and 51 deletions

View File

@@ -105,4 +105,6 @@ If you want to add a new feature that's not in [the todo list](https://git.maid.
If you have updated go dependencies or added new ones, please run `go mod tidy` before commiting.
If you update structs, please run [betteralign](https://github.com/dkorunic/betteralign) to make sure memory layout is optimized.
Any security vulnerabilities should first be disclosed privately to the maintainer ([different ways to contact me are listed here](https://laptopc.at))

View File

@@ -15,14 +15,14 @@ import (
const defaultPartsCapacity = 24
type reader struct {
parts [][]byte
leftover []byte
index int
duration *uint32
req *fasthttp.Request
resp *fasthttp.Response
client *fasthttp.HostClient
parts [][]byte
leftover []byte
index int
}
var readerpool = sync.Pool{

View File

@@ -13,18 +13,18 @@ type PlaylistOrUser struct {
Kind string `json:"kind"` // "playlist" or "system-playlist" or "user"
Permalink string `json:"permalink"`
// User-specific
Avatar string `json:"avatar_url"`
Username string `json:"username"`
FullName string `json:"full_name"`
// Playlist-specific
TrackCount int64 `json:"track_count"`
Title string `json:"title"`
Author struct {
Permalink string
} `json:"author"`
Artwork string `json:"artwork_url"`
// User-specific
Avatar string `json:"avatar_url"`
Username string `json:"username"`
FullName string `json:"full_name"`
TrackCount int64 `json:"track_count"`
}
func (p PlaylistOrUser) Href() string {

View File

@@ -18,9 +18,9 @@ import (
)
type clientIdCache struct {
NextCheck time.Time
ClientID string
Version string
NextCheck time.Time
}
var ClientIDCache clientIdCache
@@ -342,9 +342,9 @@ func Resolve(cid string, path string, out any) error {
}
type Paginated[T any] struct {
Next string `json:"next_href"`
Collection []T `json:"collection"`
Total int64 `json:"total_results"`
Next string `json:"next_href"`
}
func (p *Paginated[T]) Proceed(cid string, shouldUnfold bool) error {

View File

@@ -21,18 +21,16 @@ type Playlist struct {
Description string `json:"description"`
Kind string `json:"kind"` // should always be "playlist"! or "system-playlist"
LastModified string `json:"last_modified"`
Likes int64 `json:"likes_count"`
Permalink string `json:"permalink"`
//ReleaseDate string `json:"release_date"`
TagList string `json:"tag_list"`
Title string `json:"title"`
Type string `json:"set_type"`
Album bool `json:"is_album"`
Author User `json:"user"`
Tracks []Track `json:"tracks"`
TrackCount int64 `json:"track_count"`
MissingTracks string `json:"-"`
Tracks []Track `json:"tracks"`
Author User `json:"user"`
Likes int64 `json:"likes_count"`
TrackCount int64 `json:"track_count"`
Album bool `json:"is_album"`
}
func GetPlaylist(cid string, permalink string) (Playlist, error) {

View File

@@ -25,26 +25,26 @@ var tracksCacheLock = &sync.RWMutex{}
type Track struct {
Artwork string `json:"artwork_url"`
Comments int `json:"comment_count"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
Duration uint32 `json:"full_duration"`
Genre string `json:"genre"`
Kind string `json:"kind"` // should always be "track"!
LastModified string `json:"last_modified"`
License string `json:"license"`
Likes int64 `json:"likes_count"`
Permalink string `json:"permalink"`
Played int64 `json:"playback_count"`
Reposted int64 `json:"reposts_count"`
TagList string `json:"tag_list"`
Title string `json:"title"`
ID json.Number `json:"id"`
Media Media `json:"media"`
Authorization string `json:"track_authorization"`
Author User `json:"user"`
Policy TrackPolicy `json:"policy"`
Station string `json:"station_permalink"`
Media Media `json:"media"`
Author User `json:"user"`
Comments int `json:"comment_count"`
Likes int64 `json:"likes_count"`
Played int64 `json:"playback_count"`
Reposted int64 `json:"reposts_count"`
Duration uint32 `json:"full_duration"`
}
type TrackPolicy string
@@ -89,8 +89,8 @@ type Stream struct {
type Comment struct {
Kind string `json:"kind"` // "comment"
Body string `json:"body"`
Timestamp int `json:"timestamp"`
Author User `json:"user"`
Timestamp int `json:"timestamp"`
}
func (m Media) SelectCompatible(mode string, opus bool) (*Transcoding, string) {

View File

@@ -23,21 +23,20 @@ type User struct {
Avatar string `json:"avatar_url"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
Followers int64 `json:"followers_count"`
Following int64 `json:"followings_count"`
FullName string `json:"full_name"`
Kind string `json:"kind"` // should always be "user"!
LastModified string `json:"last_modified"`
Liked int64 `json:"likes_count"`
Permalink string `json:"permalink"`
Playlists int64 `json:"playlist_count"`
Tracks int64 `json:"track_count"`
ID json.Number `json:"id"`
Username string `json:"username"`
Verified bool `json:"verified"`
Station string `json:"station_permalink"`
WebProfiles []Link `json:",omitempty"`
Followers int64 `json:"followers_count"`
Following int64 `json:"followings_count"`
Liked int64 `json:"likes_count"`
Playlists int64 `json:"playlist_count"`
Tracks int64 `json:"track_count"`
Verified bool `json:"verified"`
}
type Link struct {
@@ -54,10 +53,9 @@ const (
// not worthy of its own file
type Repost struct {
Type RepostType
Track *Track // type == track-report
Playlist *Playlist // type == playlist-repost
Type RepostType
}
func (r Repost) Fix(prefs cfg.Preferences) {

View File

@@ -554,13 +554,13 @@ Disallow: /`)
if cfg.InstanceInfo {
type info struct {
DefaultPreferences cfg.Preferences
Commit string
Repo string
ProxyImages bool
ProxyStreams bool
Restream bool
GetWebProfiles bool
DefaultPreferences cfg.Preferences
EnableAPI bool
}