Skip to content
Snippets Groups Projects
Commit e15ae399 authored by Georges Racinet's avatar Georges Racinet
Browse files

load_repo: avoid useless ui object copy

Found out while investigating heptapod#466 that actually
the machinery behind `hg.repository` actually performs a
copy on its own. Our copy was adding pressure on the
Python memory system. This does not cure the memory leak,
but it saves about 2MB of leak over 1000 requests, even though
it doesn't change the fact that none of these ui instances
are actually collected (seen through instrumentation not
part of this changeset).

From `localrepo.py` in Mercurial 5.6.1:

```
def makelocalrepository(baseui, path, intents=None):
    """Long docstring not cited here."""
    ui = baseui.copy()
    # Prevent copying repo configuration.
    ui.copy = baseui.copy
    (...)
```

Note that this last line actually prevents `baseui` (
would be the copy we were creating) to be freed immediately.

makelocalrepository in turn is called via this backtrace:

```
  venv/lib64/python3.9/site-packages/mercurial/hg.py(221)repository()
-> peer = _peerorrepo(
  venv/lib64/python3.9/site-packages/mercurial/hg.py(188)_peerorrepo()
-> obj = _peerlookup(path).instance(
  venv/lib64/python3.9/site-packages/mercurial/localrepo.py(3214)instance()
-> return makelocalrepository(ui, localpath, intents=intents)
> venv/lib64/python3.9/site-packages/mercurial/localrepo.py(517)makelocalrepository()
-> ui = baseui.copy()

```
parent 09d6901c
No related branches found
No related tags found
2 merge requests!59Mitigate strongly memory leaks related to repository classes,!58server: mono-process mode
......@@ -69,5 +69,4 @@
repo_path = os.path.join(root_dir, rpath.encode('ascii'))
logger.info("loading repo at %r", repo_path)
# ensure caller gets private copy of ui
try:
......@@ -73,5 +72,5 @@
try:
repo = hg.repository(self.ui.copy(), repo_path)
repo = hg.repository(self.ui, repo_path)
except error.RepoError as exc:
context.set_code(StatusCode.NOT_FOUND)
context.set_details(repr(exc.args))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment