Skip to content

Commit

Permalink
CacheType: convert to uint8
Browse files Browse the repository at this point in the history
We only need ~2 bits for the types of cache. `int` is 64-bits on 64-bit
platforms, which is significant overkill.

Convert CacheType to a uint8 and move it to the end of the `cache`
struct so it only affects alignment, but not the actual size. (we can
pack in other small values at the end later as well)
  • Loading branch information
dfinkel committed Dec 9, 2019
1 parent 2bb6b74 commit 061a0ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cachetype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions galaxycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func (g *Galaxy) populateCache(ctx context.Context, key string, value *valWithSt
}

// CacheType represents a type of cache.
type CacheType int
type CacheType uint8

const (
// MainCache is the cache for items that this peer is the
Expand Down Expand Up @@ -627,12 +627,12 @@ func (g *Galaxy) CacheStats(which CacheType) CacheStats {
// and counts the size of all keys and values. Candidate cache only
// utilizes the lru.Cache and mutex, not the included stats.
type cache struct {
ctype CacheType
mu sync.Mutex
nbytes int64 // of all keys and values
lru *lru.Cache
nhit, nget int64
nevict int64 // number of evictions
ctype CacheType
}

func (c *cache) stats() CacheStats {
Expand Down

0 comments on commit 061a0ea

Please sign in to comment.