Skip to content

Conversation

@milahu
Copy link
Contributor

@milahu milahu commented Dec 20, 2020

benefit: make snapshots smaller

@jtenner
Copy link
Collaborator

jtenner commented Dec 21, 2020

Believe it or not this impacts cpu performance, probably causing v8 to have a harder time optimizing this function. Considering it will be a high traffic function and this would be considered a micro-optimization, I would request some speed metrics to validate the "if" branch is actually faster.

@milahu
Copy link
Contributor Author

milahu commented Dec 21, 2020

Believe it or not this impacts cpu performance

yes i believe that ; ) good old space-time-tradeoff

to solve the problem at its root:
we could keep track of the ctx._transformStack
and make getTransformSlice return undefined
if the current transform is the identity transform
( canvas._transformIsIdentic == true )
so that createCanvasEvent can omit the transform field

replay the recorded API calls - this should be a separate issue

for my app, it would be ideal to save the capture as JS code, like

// var c = document.createElement('canvas')
// var x = c.getContext('2d')
x.drawFoo()
x.drawBar()
  var p = new Path2D()
  p.drawSome()
  p.drawThing()
    var p1 = new Path2D()
    p1.drawAnother()
    p1.drawThing()
  p.addPath(p1)
x.addPath(p)
// ....

then the consumer can simply call eval('x.drawFoo()')

or encapsulate/compile frames into functions
like var f = new Function('x', 'x.drawFoo()') and call f(ctx)

edit: i dont need prop-objects like { x: 1, y: 2, foo: "three", bar: null }
and im happy with positional argument arrays like [ 1, 2, "three", null ]
= less overhead for most consumers

@milahu
Copy link
Contributor Author

milahu commented Dec 21, 2020

closing for #77

@milahu milahu closed this Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants