diff options
author | Eddie Elizondo <eduardo.elizondorueda@gmail.com> | 2023-04-22 19:39:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 19:39:37 (GMT) |
commit | ea2c0016502472aa8baa3149050ada776d17a009 (patch) | |
tree | e9e3935a9b71a1f88ac18c24fe512d199880ff90 /Lib/test/libregrtest | |
parent | 916de04fd1838530096336aadb3b94b774ed6c90 (diff) | |
download | cpython-ea2c0016502472aa8baa3149050ada776d17a009.zip cpython-ea2c0016502472aa8baa3149050ada776d17a009.tar.gz cpython-ea2c0016502472aa8baa3149050ada776d17a009.tar.bz2 |
gh-84436: Implement Immortal Objects (gh-19474)
This is the implementation of PEP683
Motivation:
The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime.
Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
Diffstat (limited to 'Lib/test/libregrtest')
-rw-r--r-- | Lib/test/libregrtest/refleak.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py index 4298fa8..2de8c6c 100644 --- a/Lib/test/libregrtest/refleak.py +++ b/Lib/test/libregrtest/refleak.py @@ -73,9 +73,10 @@ def dash_R(ns, test_name, test_func): fd_deltas = [0] * repcount getallocatedblocks = sys.getallocatedblocks gettotalrefcount = sys.gettotalrefcount + getunicodeinternedsize = sys.getunicodeinternedsize fd_count = os_helper.fd_count # initialize variables to make pyflakes quiet - rc_before = alloc_before = fd_before = 0 + rc_before = alloc_before = fd_before = interned_before = 0 if not ns.quiet: print("beginning", repcount, "repetitions", file=sys.stderr) @@ -91,9 +92,13 @@ def dash_R(ns, test_name, test_func): dash_R_cleanup(fs, ps, pic, zdc, abcs) support.gc_collect() - # Read memory statistics immediately after the garbage collection - alloc_after = getallocatedblocks() - rc_after = gettotalrefcount() + # Read memory statistics immediately after the garbage collection. + # Also, readjust the reference counts and alloc blocks by ignoring + # any strings that might have been interned during test_func. These + # strings will be deallocated at runtime shutdown + interned_after = getunicodeinternedsize() + alloc_after = getallocatedblocks() - interned_after + rc_after = gettotalrefcount() - interned_after * 2 fd_after = fd_count() if not ns.quiet: @@ -106,6 +111,7 @@ def dash_R(ns, test_name, test_func): alloc_before = alloc_after rc_before = rc_after fd_before = fd_after + interned_before = interned_after if not ns.quiet: print(file=sys.stderr) |