Problem
CGO is used to compile the Go code into a C Library, there seem to be a a considerable overhead1, there are many calls going to go
Specifically these are the calls which call the go code
env.setup()
- called 1
env.reset()
- called 1 per game
env.step()
- called 1 per turn
env.render()
- called 1 per turn
env_done()
- called 1 per turn
The 3 functions, We are mainly intrested in to optimize is the step
, render
and env_done
functions.
Solutions
Render
If we could implement the render in python, we would save 1 call. This already possible as the environments contain the information needed (cached from step)
To create the rendere something like Textualize could be utilized, this would also allow us to show multiple games at once, once vectorization is added.
env_done
we can implement this in python as well, since this can be be using the cached response from the go environment.
The code below is what is returned of the step function and is cached in the enviorment:
|
type StepRes struct { |
|
Done bool `json:"done"` |
|
Reward int `json:"reward"` |
|
Info interface{} `json:"info"` |
|
Observation client.SnakeRequest `json:"observation"` |
|
} |
Step
This is the only function we can't move out of go, it might not be worth optimizing this code a lot, because vectorization (running multiple environments at once) would speed up training.
That being said, it will be worth comparing these 2 libraries :
As any substantial performance increase, would help speed up training and even more when vectorization is utilized
References