Many enterprises like to use Dynamsoft Barcode Reader SDK due to its flexible parameter configuration and powerful decoding capability for multiple barcodes. In this article, let’s take a glimpse of the barcode SDK template and the possible way to optimize the decoding performance from a developer’s angle.
How to Configure Templates for Decoding Performance
If you have never tried Dynamsoft Barcode Reader SDK, you can have fun with the online barcode playground, simply changing the mode to compare the performance difference straightforwardly.

Furthermore, if you are an expert, you can click advanced settings to adjust a bunch of parameters by yourself.
To facilitate developers, I have uploaded five useful template files to Github:
Decoding speed or decoding accuracy? You can balance the trade-off depends on specific usage scenarios.
Here is my testing image:

Let’s see the detection accuracy and time cost by using the different templates:
BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt speed.json Total barcode(s) found: 12. Time cost: 63 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt balanced.json Total barcode(s) found: 13. Time cost: 140 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt coverage.json Total barcode(s) found: 13. Time cost: 844 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt morecoverage.json Total barcode(s) found: 13. Time cost: 1610 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt mostcoverage.json Total barcode(s) found: 13. Time cost: 3156 ms
As you can see, in my case, to guarantee both accuracy and decoding speed, the most suitable template is balance.json.
Is It Possible to Speeding Up Multi-Barcode Decoding Performance with Multi-thread?
In our common sense, the time cost of decoding a single barcode should be less than the time cost of decoding multi-barcodes. So a possible optimization way of reading multiple barcodes is to create multiple worker threads for processing different barcode symbologies simultaneously.
Here is the code for decoding 1D and 2D barcodes sequentially:
barcode_decoding(buffer, size, BF_CODE_39, 1, license, config); barcode_decoding(buffer, size, BF_QR_CODE, 1, license, config); barcode_decoding(buffer, size, BF_PDF417, 1, license, config); barcode_decoding(buffer, size, BF_DATAMATRIX, 1, license, config);
The total time cost is 407ms:
Thread id: 22536. Type: CODE_39 Thread id: 22536. Total barcode(s) found: 1. Time cost: 235 ms Thread id: 22536. Type: QR_CODE Thread id: 22536. Total barcode(s) found: 1. Time cost: 47 ms Thread id: 22536. Type: PDF417 Thread id: 22536. Total barcode(s) found: 1. Time cost: 62 ms Thread id: 22536. Type: DATAMATRIX Thread id: 22536. Total barcode(s) found: 1. Time cost: 63 ms
To optimize the decoding performance, I can create four threads to do the same thing:
int starttime = gettime(); thread t1(barcode_decoding, buffer, size, BF_CODE_39, 1, license, config); thread t2(barcode_decoding, buffer, size, BF_QR_CODE, 1, license, config); thread t3(barcode_decoding, buffer, size, BF_PDF417, 1, license, config); thread t4(barcode_decoding, buffer, size, BF_DATAMATRIX, 1, license, config); t1.join(); t2.join(); t3.join(); t4.join(); int endtime = gettime(); printf("Thread time cost: %d ms\n\n", (endtime - starttime));
The final time cost is 265ms:
Thread id: 24024. Type: QR_CODE Thread id: 24024. Total barcode(s) found: 1. Time cost: 78 ms Thread id: 17384. Type: DATAMATRIX Thread id: 17384. Total barcode(s) found: 1. Time cost: 78 ms Thread id: 24264. Type: PDF417 Thread id: 24264. Total barcode(s) found: 1. Time cost: 94 ms Thread id: 4060. Type: CODE_39 Thread id: 4060. Total barcode(s) found: 1. Time cost: 265 ms Thread time cost: 265 ms
So far, it seems good. However, if you pass multiple barcode types to the Dynamsoft barcode decoding API, a magical thing will happen:
barcode_decoding(buffer, size, BF_CODE_39 | BF_DATAMATRIX | BF_QR_CODE | BF_PDF417, 1, license, config);
It is faster than your own multi-thread solution:
Thread id: 20308. Type: PDF417 Thread id: 20308. Type: QR_CODE Thread id: 20308. Type: DATAMATRIX Thread id: 20308. Type: CODE_39 Thread id: 20308. Total barcode(s) found: 4. Time cost: 250 ms
The reason is all Dynamsoft barcoding decoding APIs are implemented in threading. Therefore, you do not need to create threads for optimizing decoding performance.
How Thread Count Affects Dynamsoft Barcode SDK Performance?
You may have noticed that there is a parameter named maxAlgorithmThreadCount. Can we boost the SDK performance by increasing the thread count?
I did a simple test based on hardware threads:
const auto processor_count = std::thread::hardware_concurrency(); int minimum_count = 1, minimum_timecost = 0; for (int i = 0; i < processor_count; i++) { printf("Thread count: %d. ", i + 1); int timecost = barcode_decoding(buffer, size, formats, i, license, config); if (i == 0) { minimum_count = 1; if (timecost > 0) { minimum_timecost = timecost; } } else { if (timecost < minimum_timecost) { minimum_count = i + 1; minimum_timecost = timecost; } } } printf("Multi-thread best performance: thread_count = %d, timecost = %d \n\n", minimum_count, minimum_timecost);
Every time I ran the app, I got different results. The performances are not dramatically different by using my testing image:
Thread count: 1. Thread id: 26376. Total barcode(s) found: 13. Time cost: 141 ms Thread count: 2. Thread id: 26376. Total barcode(s) found: 13. Time cost: 141 ms Thread count: 3. Thread id: 26376. Total barcode(s) found: 13. Time cost: 125 ms Thread count: 4. Thread id: 26376. Total barcode(s) found: 13. Time cost: 140 ms Thread count: 5. Thread id: 26376. Total barcode(s) found: 13. Time cost: 157 ms Thread count: 6. Thread id: 26376. Total barcode(s) found: 13. Time cost: 203 ms Thread count: 7. Thread id: 26376. Total barcode(s) found: 13. Time cost: 156 ms Thread count: 8. Thread id: 26376. Total barcode(s) found: 13. Time cost: 140 ms Multi-thread best performance: thread_count = 3, timecost = 125
Apparently, one testing image does not make any sense. Ideally, you should measure the performance with an image dataset. So if you are interested, go and get your hands dirty now.
Source Code
https://github.com/Dynamsoft/cmake
The post How to Optimize Dynamsoft Barcode Decoding Performance with Parameters appeared first on Dynamsoft Developers.