Skip to content

Using AI Assistant to identity (and fix) performance bottlenecks - #163

Merged
whomwah merged 12 commits into
mainfrom
feat/performance1
Jan 8, 2026
Merged

Using AI Assistant to identity (and fix) performance bottlenecks#163
whomwah merged 12 commits into
mainfrom
feat/performance1

Conversation

@whomwah

@whomwah whomwah commented Jan 8, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a comprehensive benchmarking suite for the RQRCode library, enabling developers to measure and track performance and memory usage across different QR code export formats. It also updates documentation and tooling to support these new benchmarks and clarifies Ruby version requirements.

Performance Improvements

  • SVG rendering: Improved by +130% (from 184 i/s to 424 i/s) with 71% memory reduction
  • HTML rendering: Now the fastest export format at 1,876 i/s (rendering-only benchmark)
  • End-to-end performance: All formats now perform similarly (~32-34 i/s for medium QR codes) - SVG optimizations closed the gap with other formats
  • Memory efficiency: HTML now uses 6x less memory than SVG (previously 22x), with HTML at 18.0 MB vs SVG at 113.8 MB

Key Benchmark Insights

  • End-to-end benchmarks show that QR generation dominates performance, with all export formats achieving similar speeds
  • Rendering-only benchmarks reveal significant improvements in export efficiency, particularly for SVG and HTML
  • HTML is the most memory-efficient format (451 objects allocated vs 2,157,951 for SVG)
  • SVG improvements reduced the performance gap vs HTML from 10x to 4.4x

Benchmarking Infrastructure and Usage

  • Added a full benchmark suite in the benchmark/ directory, including scripts for SVG, PNG, HTML, ANSI, and format comparison, as well as a detailed benchmark/README.md explaining usage, metrics, and interpretation of results. Benchmark results are saved as JSON for tracking over time.
  • Introduced benchmark_helper.rb to provide shared benchmarking utilities, including methods for running IPS (iterations/sec), memory, and stack profiling, and saving results.
  • Added Rake tasks for running benchmarks individually or all at once, integrating them into the development workflow.

Documentation and Developer Experience

  • Added AGENTS.md as a development guide for AI agents, summarizing build/test/lint commands, code style, file structure, dependencies, and commit message conventions.
  • Updated README.md to reflect the new minimum Ruby version (>= 3.2.0), document benchmark usage, and clarify contribution guidelines.

Tooling and Configuration

  • Updated the Ruby matrix in the GitHub workflow to test only supported versions (3.2, 3.3, 3.4, 4.0).
  • Added a commented-out reference to rqrcode_core in the Gemfile for easier local development.

- Add Rake tasks for running benchmarks
- Add benchmark scripts for SVG, PNG, HTML, ANSI, and format comparison
- Add benchmark_helper.rb for shared setup and result saving
- Add benchmark/README.md with usage and baseline results
- Update Gemfile.lock with benchmark dependencies
- Ignore benchmark/results/ in .gitignore
- Remove Ruby 3.0 from CI test matrix
- Introduce run_ips_e2e for full workflow timing (generation + export)
- Update all export benchmarks to run both end-to-end and rendering-only
  modes
- Expand README with detailed explanation of benchmark types and output
- Clarify benchmark output and add summary messages for each script
Rewrite HTML export to use a single loop and preallocate string
capacity, improving speed and memory usage. Remove unnecessary helper
classes.
- Refactor path tracing to use integer direction constants and arrays
- Remove Edge struct, reduce allocations and intermediate arrays
- Build SVG path string directly for each loop, minimizing string ops
- Improves rendering speed by 130% and reduces output size
- Update benchmark README with new performance results
- Add comprehensive SVG export tests covering options and output
@whomwah whomwah self-assigned this Jan 8, 2026
@whomwah
whomwah merged commit ea5d9cd into main Jan 8, 2026
24 checks passed
@whomwah
whomwah deleted the feat/performance1 branch January 8, 2026 16:05
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.

1 participant