Closed RexWzh closed 1 year ago
Base: 99.70% // Head: 100.00% // Increases project coverage by +0.29%
:tada:
Coverage data is based on head (
98261cb
) compared to base (f02ba74
). Patch coverage: 100.00% of modified lines in pull request are covered.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
The result looks great! I'm pretty busy here so can't do a review right now.
But feel free to merge if you're confident. I can do an after-merge review when I find some time and it's always possible to fix potential issues (if there were) afterward.
Just want to point out (without digging into the details) that 14194 allocations: 746.17 KiB
often indicates some performance tweak room by reducing memory allocations. Maybe there are some loops that you can pre-allocate a buffer array and reuse it? Type instability can also cause these many allocations.
Just want to point out (without digging into the details) that 14194 allocations: 746.17 KiB often indicates some performance tweak room by reducing memory allocations. Maybe there are some loops that you can pre-allocate a buffer array and reuse it?
Good advice!!
Here is the benchmark result after rewriting the function penalty
. (use @view
to index sub-matrices and edit other details)
mode | input string | cost |
---|---|---|
Byte | "Hello world!" | 142.909 μs (370 allocations: 32.23 KiB) |
Numeric | "0123456789" ^ 30 | 1.454 ms (1982 allocations: 291.95 KiB) |
Alphanumeric | "HELLO WORLD" ^ 30 | 2.495 ms (3200 allocations: 562.52 KiB) |
max version | "HELLO WORLD" ^ 190 | 14.310 ms (17825 allocations: 3.01 MiB) |
qrcode
message = "Hello world!"
eclevel, mode = Medium(), getmode(message)
version = getversion(message, mode, eclevel)
data = @btime encodemessage(message, mode, eclevel, version) # test 1
matrix = emptymatrix(version)
masks = @btime makemasks(matrix) # test 2
matrix = placedata!(matrix, data)
addversion!(matrix, version) # fill in version bits
maskedmats = @btime [addformat!(xor.(matrix, mat), i-1, eclevel) for (i, mat) in enumerate(masks)]; # test 3
mask = @btime argmin(penalty.(maskedmats)) - 1 # test 4
matrix = maskedmats[mask + 1]
Benchmark results of main steps: | function | cost |
---|---|---|
encodemessage |
13.925 μs (238 allocations: 22.75 KiB) |
|
8 * makemask |
5.445 μs (18 allocations: 1.38 KiB) |
|
8 * addformat! |
5.631 μs (51 allocations: 2.64 KiB) |
|
8 * penalty |
106.084 μs (52 allocations: 3.94 KiB) |
Some notes:
encodemessage
might be used for type conversion:
msg => bits => integers(RS encoding) => bits
penalty
has four conditions, the third one cost the most.(15 + 17 + 65 + 1.3)# Condition 3: specific patterns in rows or columns
patt1 = BitArray([1, 0, 1, 1, 1, 0, 1, 0, 0, 0 ,0])
patt2 = BitArray([0, 0, 0 ,0, 1, 0, 1, 1, 1, 0, 1])
function check(i, j)
hline = @view(matrix[i, j:j + 10])
vline = @view(matrix[j:j + 10, i])
return (hline == patt1 || hline == patt2) + (vline == patt1 || vline == patt2)
end
p3 = 40 * sum(check(i, j) for i in 1:n for j in 1:(n-10))
I think this repo is ready to be registered. After that, it might be more convenient for QRDecoders.jl to include this package.
Compare with QRCode.jl
406.058 μs (14194 allocations: 746.17 KiB)
3.098 ms (100030 allocations: 5.09 MiB)
5.094 ms (160384 allocations: 8.23 MiB)
33.779 ms (922529 allocations: 46.93 MiB)
4.011 ms (175888 allocations: 8.43 MiB)
25.891 ms (1043655 allocations: 50.04 MiB)
38.452 ms (1567245 allocations: 75.29 MiB)
304.884 ms (12002957 allocations: 577.33 MiB)
I'll try to register the package here. Thanks for the advice during the period and for this opportunity to get involved in the project.! @johnnychen94 :)