Skip to content

Commit

Permalink
Only take the slow-path in MutationCmdsFor if we really have to.
Browse files Browse the repository at this point in the history
This saves us a bunch of performance since for the most part
we never have to hit the slow-path. This is especially
true for GLES.
  • Loading branch information
AWoloszyn committed Sep 13, 2018
1 parent 7e798ae commit df224c7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions gapis/api/gvr/gvr.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (API) FlattenSubcommandIdx(idx api.SubCmdIdx, data *sync.Data, unused bool)
return api.CmdID(0), false
}

// IsTrivialTerminator returns true if the terminator is just stopping at the given index
func (API) IsTrivialTerminator(ctx context.Context, p *path.Capture, command api.SubCmdIdx) (bool, error) {
return true, nil
}

// RecoverMidExecutionCommand returns a virtual command, used to describe the
// a subcommand that was created before the start of the trace
// GVR has no subcommands of this type, so this should never be called
Expand Down
16 changes: 14 additions & 2 deletions gapis/api/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type SynchronizedAPI interface {
// a subcommand that was created before the start of the trace.
// If the api does not have mid-execution commands, NoMECSubcommandsError should be returned.
RecoverMidExecutionCommand(ctx context.Context, c *path.Capture, data interface{}) (api.Cmd, error)

// IsTrivialTerminator returns true if stopping at the given command is trivial.
IsTrivialTerminator(ctx context.Context, c *path.Capture, cmd api.SubCmdIdx) (bool, error)
}

type writer struct {
Expand Down Expand Up @@ -112,13 +115,19 @@ func MutationCmdsFor(ctx context.Context, c *path.Capture, data *Data, cmds []ap

terminators := make([]transform.Terminator, 0)
transforms := transform.Transforms{}

isTrivial := true
for _, api := range rc.APIs {
if sync, ok := api.(SynchronizedAPI); ok {
term, err := sync.GetTerminator(ctx, c)
if err != nil {
return nil, err
}

t, err := sync.IsTrivialTerminator(ctx, c, fullCommand)
if err != nil {
return nil, err
}
isTrivial = t && isTrivial
if term != nil {
terminators = append(terminators, term)
continue
Expand All @@ -132,9 +141,12 @@ func MutationCmdsFor(ctx context.Context, c *path.Capture, data *Data, cmds []ap
}
transforms.Add(t)
}

if isTrivial {
return cmds[0:id], nil
}
w := &writer{rc.NewState(ctx), nil}
transforms.Transform(ctx, cmds, w)

return w.cmds, nil
}

Expand Down
24 changes: 24 additions & 0 deletions gapis/api/vulkan/vulkan.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,30 @@ func (API) FlattenSubcommandIdx(idx api.SubCmdIdx, data *sync.Data, initialCall
return api.CmdID(0), false
}

// IsTrivialTerminator returns true if the terminator is just stopping at the given index
func (API) IsTrivialTerminator(ctx context.Context, p *path.Capture, after api.SubCmdIdx) (bool, error) {
s, err := resolve.SyncData(ctx, p)
if err != nil {
return false, err
}

if len(after) == 1 {
a := api.CmdID(after[0])
// If we are not running subcommands we can probably batch
for _, v := range s.SortedKeys() {
if v > a {
return true, nil
}
for _, k := range s.CommandRanges[v].SortedKeys() {
if k > a {
return false, nil
}
}
}
}
return false, nil
}

// RecoverMidExecutionCommand returns a virtual command, used to describe the
// a subcommand that was created before the start of the trace
func (API) RecoverMidExecutionCommand(ctx context.Context, c *path.Capture, dat interface{}) (api.Cmd, error) {
Expand Down

0 comments on commit df224c7

Please sign in to comment.