Skip to content

Commit

Permalink
session: fix a performance regression (#6008)
Browse files Browse the repository at this point in the history
firing lots of spurious events was leading to some problems

Signed-off-by: Nick Santos <[email protected]>

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Jan 9, 2023
1 parent 8d4e1b4 commit 72e0e98
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
3 changes: 1 addition & 2 deletions internal/controllers/core/session/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil
}

r.st.Dispatch(sessions.NewSessionUpsertAction(session))
return r.maybeUpdateObjectStatus(ctx, session)
}

Expand All @@ -88,7 +87,7 @@ func (r *Reconciler) maybeUpdateObjectStatus(ctx context.Context, session *v1alp
if err != nil {
return ctrl.Result{}, err
}
r.st.Dispatch(sessions.NewSessionUpsertAction(update))
r.st.Dispatch(sessions.NewSessionStatusUpdateAction(update))
return result, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/engine/upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func upperReducerFn(ctx context.Context, state *store.EngineState, action store.
handlePanicAction(state, action)
case store.LogAction:
handleLogAction(state, action)
case sessions.SessionUpsertAction:
sessions.HandleSessionUpsertAction(state, action)
case sessions.SessionStatusUpdateAction:
sessions.HandleSessionStatusUpdateAction(state, action)
case prompt.SwitchTerminalModeAction:
handleSwitchTerminalModeAction(state, action)
case server.OverrideTriggerModeAction:
Expand Down
18 changes: 5 additions & 13 deletions internal/store/sessions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@ package sessions
import (
"errors"

"k8s.io/apimachinery/pkg/types"

"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
)

type SessionUpsertAction struct {
type SessionStatusUpdateAction struct {
Object *v1alpha1.Session
}

func (SessionUpsertAction) Action() {}

var _ store.Summarizer = SessionUpsertAction{}

func (a SessionUpsertAction) Summarize(summary *store.ChangeSummary) {
summary.Sessions.Add(types.NamespacedName{Namespace: a.Object.ObjectMeta.Namespace, Name: a.Object.ObjectMeta.Name})
}
func (SessionStatusUpdateAction) Action() {}

func NewSessionUpsertAction(session *v1alpha1.Session) SessionUpsertAction {
return SessionUpsertAction{Object: session}
func NewSessionStatusUpdateAction(session *v1alpha1.Session) SessionStatusUpdateAction {
return SessionStatusUpdateAction{Object: session}
}

func HandleSessionUpsertAction(state *store.EngineState, action SessionUpsertAction) {
func HandleSessionStatusUpdateAction(state *store.EngineState, action SessionStatusUpdateAction) {
status := action.Object.Status
if status.Done {
state.ExitSignal = true
Expand Down
4 changes: 0 additions & 4 deletions internal/store/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ type ChangeSummary struct {
// Cmds with their specs changed.
CmdSpecs ChangeSet

// Sessions that have changed.
Sessions ChangeSet

UISessions ChangeSet
UIResources ChangeSet
UIButtons ChangeSet
Expand All @@ -79,7 +76,6 @@ func (s *ChangeSummary) Add(other ChangeSummary) {
s.Legacy = s.Legacy || other.Legacy
s.Log = s.Log || other.Log
s.CmdSpecs.AddAll(other.CmdSpecs)
s.Sessions.AddAll(other.Sessions)
s.UISessions.AddAll(other.UISessions)
s.UIResources.AddAll(other.UIResources)
s.Clusters.AddAll(other.Clusters)
Expand Down

0 comments on commit 72e0e98

Please sign in to comment.