Skip to content

1.9.0

Latest

Choose a tag to compare

@soya-daizu soya-daizu released this 18 Nov 08:38

This release makes the encoder about 4× faster with far fewer allocations, and fixes a number of bugs in QR Code version 40, Micro QR Code and rMQR Code.

Breaking changes

  • Crystal 1.16.0 or later is now required (previously 1.13.0), so that constant tables can be stored with Slice.literal.
  • Generated QR Code symbols may differ from 1.8.0. The mask penalty rules N3 (finder-like patterns at the symbol edges) and N4 (rounding of the dark module ratio) are now computed as the specification defines, so a different mask can be chosen for the same input. The symbols remain valid and decode to the same data.
  • The -Dpreview_mt code path for parallel mask selection has been removed. Scoring a mask now takes only a few microseconds, so spawning fibers costs more than it saves.

Bug fixes

  • QR
    • Version information was missing in version 40 symbols
    • Mask penalty N3 at the symbol edges and N4 rounding
  • MQR
    • Placement and padding of the 4-bit codeword in M1 and M3 symbols
    • Decoder reading past the end of the bit stream when looking ahead for the terminator
  • rMQR
    • Wrong alignment pattern positions
    • Format information table truncated to 8 bits
    • Data placement skipping columns 0 and 1
  • Error correction
    • GF.log(1) returned 255 instead of 0, which broke correction of an error in the last codeword
  • Others
    • Decoders no longer mutate the input canvas
    • The accumulated bit length is now checked when appending segments
    • Fixed the error message of BitStream#read_bits

Performance

Encoding is about 4.4× faster and allocates about 70% less memory than 1.8.0. Goban is now faster than libqrencode (via qrencode.cr) and 30-60× faster than spider-gazelle/qr-code; see the benchmarks in README.

Goban::QR.encode_string("Hello World!", Goban::ECC::Level::High)
Version Speed Memory
1.8.0 30.76k ips (32.51µs) 7.6kB/op
1.9.0 133.78k ips (7.48µs) 2.29kB/op
  • Mask penalty scores are evaluated with bit-parallel operations on packed rows and columns (2-7.6× faster scoring)
  • Mask selection works on packed bit lines and builds the final canvas from the chosen candidate without cloning the canvas
  • Text is classified once and segmentation results are cached per indicator lengths; slicing multibyte text is no longer quadratic
  • Versions whose capacity is below a lower bound of the data bits are skipped without segmenting
  • Bits are written in chunks, and Reed-Solomon ECC is computed in place with an LFSR
  • Tables keyed by EC level are looked up with a compile-time key
  • The Shift JIS table is embedded in the read-only data section as a Slice.literal, so it needs no runtime initialization and the binary is 100KB+ smaller.

Tests & CI

  • Added encode/decode round-trip fuzz tests, and round-trip tests for every version and EC level of QR, Micro QR and rMQR
  • Added interoperability tests against symbols generated by libqrencode 4.1.1

Full Changelog: 1.8.0...1.9.0