| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
So far, LGTM, though I am curious about concurrency safety in eliding a critical section when copying a frozendict, especially with a free-threaded interpreter
Sorry, something went wrong.
|
Microbenchmark on frozendict | frozendict2 with 50 threads: Detailsimport threading
import time
import pyperf
import sys
KEYS = 4_096
LOOPS = 2 ** 9
NTHREAD = 50
code = f"fd = frozendict({', '.join(f'key{key}=1' for key in range(KEYS))})"
exec(code)
assert(len(fd) == KEYS)
assert(all(sys._is_immortal(key) for key in fd.keys()))
fd2 = frozendict(x=1, y=2, z=3)
class Worker(threading.Thread):
def __init__(self, fd, fd2):
super().__init__()
self.copies = 0
self.fd = fd
self.fd2 = fd2
def run(self):
fd = self.fd
fd2 = self.fd2
for _ in range(LOOPS):
join = fd | fd2
def bench(fd, fd2):
threads = [Worker(fd, fd2) for _ in range(NTHREAD)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
runner = pyperf.Runner()
runner.bench_func('bench', bench, fd, fd2)Benchmark result: Mean +- std dev: [ref] 554 ms +- 15 ms -> [optim] 112 ms +- 4 ms: 4.95x faster I ran the benchmark on Fedora 43 on my laptop with 12 threads (6 CPU cores) on a free-threaded Python build. |
Sorry, something went wrong.
A frozendict mapping is immutable so a critical section is not needed to ensure that a copy is consistent. |
Sorry, something went wrong.
|
This change increases the scalability on the following operations:
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.