Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Make evaluations faster by optimising python stack access

Open harelbacoralogix opened this issue 4 years ago • 0 comments

Hi,

Currently jseval.Eval performs an inspect.stack() in order to access the f_local var up the stack (3 stacks ago). This is done through:

local_scope = inspect.stack()[3][0].f_locals['var']

However, playing around with trying to optimise evaluation, it seems the following is equivalent and considerably more efficient:

local_scope = inspect.currentframe().f_back.f_back.f_back.f_locals['var']

Testing on my use case (~5000 calls to eval, but obviously with a lot of other stuff around it), this single modification has cut down processing times by more than a 45%.

Thought that it would be an interesting optimisation that can help a lot of use cases.

I would be glad to issue a pull-request on this, but this would take around 2 months, since i'm going offline for a long vacation today.

btw, you've done extremely great work on this library.

Harel

harelbacoralogix avatar Sep 03 '21 10:09 harelbacoralogix