JuliaPy / JuliaPy/PyCall.jl

Intern frequently used PyObject?

Open
#259 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
1.5k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

While examing the `gc` of my code I saw a LOT of PyObject being created and garbage collected. (I modified `PyCall` so as to print the object at finalizing)

I am wondering if `PyCall` can automatically cache many frequently used objects, such as

```
PyObject([])
PyObject(None)
PyObject(True)
PyObject(False)
```

and maybe even `PyObject(0), ... PyObject(255)`.

For example, I have a [Julia wrapper](https://github.com/colinfang/PyLogging.jl) for python `logging`. Each logging would generate 7 `PyObjects`. That's a bit too many.

```
julia> PyLogging.basicConfig()

julia> @warning logger "ll"
WARNING:root:ll

julia> gc()
"Start pydecref PyObject (30,)"
"Start pydecref PyObject True"
"Start pydecref PyObject 30"
"Start pydecref PyObject 'll'"
"Start pydecref PyObject []"
"Start pydecref PyObject (30, 'll', [])"
"Start pydecref PyObject None"
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.