Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vimeo/galaxycache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.2
Choose a base ref
...
head repository: vimeo/galaxycache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 3 files changed
  • 2 contributors

Commits on Apr 9, 2024

  1. protocodec: make a few tweaks to allow inlining

    protocodec.GalaxyGet is particularly hot, and trivial so it should get
    inlined. Make a few tweaks to allow inlining. (bringing the cost down
    below the magic 80 number in the go compiler)
    
    Similarly, split up protocodec.backendGetterV2.Get to allow inlining of
    the fast path. (Amusingly, this also allows the new `setSlow` to inline,
    but that wasn't the goal)
    dfinkel committed Apr 9, 2024
    Copy the full SHA
    f34785d View commit details
  2. Copy the full SHA
    592bfb1 View commit details
  3. Merge pull request #45 from vimeo/protocodec_inline_optimizations

    protocodec: make a few tweaks to allow inlining
    dfinkel authored Apr 9, 2024
    Copy the full SHA
    efe6cae View commit details
  4. Merge pull request #46 from vimeo/ghactions_go1.22

    actions: add go 1.21 and 1.22
    dfinkel authored Apr 9, 2024
    Copy the full SHA
    cb54caf View commit details

Commits on Nov 19, 2024

  1. actions: add go 1.23 to test matrix

    Go 1.23 is now commonplace. Include it in the test matrix.
    dfinkel committed Nov 19, 2024
    Copy the full SHA
    4df8545 View commit details
  2. Merge pull request #48 from vimeo/go1.23-bump

    actions: add go 1.23 to test matrix
    dfinkel authored Nov 19, 2024
    Copy the full SHA
    5440c82 View commit details
Showing with 21 additions and 18 deletions.
  1. +2 −2 .github/workflows/go.yml
  2. +14 −11 protocodec/backend_getter_v2.go
  3. +5 −5 protocodec/galaxywrap_v2.go
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
goversion: [1.17, 1.18, '1.19', '1.20']
goversion: [1.17, 1.18, '1.19', '1.20', '1.21', '1.22', '1.23']
steps:
- name: Set up Go ${{matrix.goversion}} on ${{matrix.os}}
uses: actions/setup-go@v3
@@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v1

- name: gofmt
if: ${{matrix.goversion == '1.20'}}
if: ${{matrix.goversion == '1.23'}}
run: |
[[ -z $(gofmt -l $(find . -name '*.go') ) ]]
25 changes: 14 additions & 11 deletions protocodec/backend_getter_v2.go
Original file line number Diff line number Diff line change
@@ -30,19 +30,22 @@ func (b backendGetterV2[C, T]) Get(ctx context.Context, key string, dest galaxyc
if bgErr != nil {
return bgErr
}
switch d := dest.(type) {
case *CodecV2[C, T]:
if d, ok := dest.(*CodecV2[C, T]); ok {
d.Set(out)
default:
vs, mErr := proto.Marshal(out)
if mErr != nil {
return fmt.Errorf("failed to marshal value as bytes: %w", mErr)
}

if uErr := dest.UnmarshalBinary(vs); uErr != nil {
return fmt.Errorf("destination codec (type %T) Unmarshal failed: %w", dest, uErr)
}
return nil
}
return b.setSlow(out, dest)

}

func (b backendGetterV2[C, T]) setSlow(out T, dest galaxycache.Codec) error {
vs, mErr := proto.Marshal(out)
if mErr != nil {
return fmt.Errorf("failed to marshal value as bytes: %w", mErr)
}

if uErr := dest.UnmarshalBinary(vs); uErr != nil {
return fmt.Errorf("destination codec (type %T) Unmarshal failed: %w", dest, uErr)
}
return nil
}
10 changes: 5 additions & 5 deletions protocodec/galaxywrap_v2.go
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ import (

// GalaxyGet is a simple wrapper around a Galaxy.Get method-call that takes
// care of constructing the protocodec.CodecV2, etc. (making the interface more idiomatic for Go)
func GalaxyGet[C any, T pointerMessage[C]](ctx context.Context, g *galaxycache.Galaxy, key string) (T, error) {
pc := NewV2[C, T]()
getErr := g.Get(ctx, key, &pc)
func GalaxyGet[C any, T pointerMessage[C]](ctx context.Context, g *galaxycache.Galaxy, key string) (m T, getErr error) {
pc := CodecV2[C, T]{}
getErr = g.Get(ctx, key, &pc)
if getErr != nil {
return nil, getErr
return // use named return values to bring the inlining cost down
}
return pc.Get(), nil
return pc.msg, nil
}