Skip to content

Python Multithreading Support via GIL #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

billmccartney
Copy link
Contributor

Enabled parallel Python support by disabling the GIL during ReadBarcodes. This allows multiple threads to decode different images at the same time in Python.
pybind11 notes are here https://pybind11.readthedocs.io/en/stable/advanced/misc.html#global-interpreter-lock-gil

Enabled parallel Python support by disabling the GIL during ReadBarcodes. This allows multiple threads to decode different images at the same time in Python.
@axxel
Copy link
Collaborator

axxel commented Sep 12, 2023

Thanks for your contribution. Question: do you have a use case where this actually increases your throughput? If so, how big are your input images?

@billmccartney
Copy link
Contributor Author

I ran a few benchmarks, and the throughput improvement is nearly linear per core (I have 8 cores for the numbers below). For testing out the 200x193 I used 10k images and for the 1919x2670 I used 100 images.

resolution (200, 193)
time 0.6368 seconds after unlocking GIL vs 4.279 seconds on master
resolution (1919, 2670)
time 1.227 seconds after unlocking GIL vs 9.349 seconds on master

pool = ThreadPoolExecutor(max_workers=os.cpu_count())
t1 = time.time()
output = list(pool.map(lambda x: zxingcpp.read_barcode(x), ims))
t2 = time.time()

Not sure how familiar you are with Python -- essentially with the GIL locked no other python code can execute in any other threads.

My specific application is automated inspection in electronics manufacturing -- camera array scanning labels from panels of circuit boards. I need to scan ~40 barcodes in real-time, but it's grossly parallel.

@axxel axxel merged commit 564dda9 into zxing-cpp:master Sep 13, 2023
@axxel
Copy link
Collaborator

axxel commented Sep 13, 2023

Thanks for your benchmarking information. Makes your change look obviously very worthwhile. :). If you care about performance, make sure you only look for symbologies (BarcodeFormats) that you are actually interested in. It sounds like you have a rather standardized set of input images. I'd be interested to see a sample if possible, maybe I can provide more tips on how to improve the performance for that type of input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy