Skip to content
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

Feature: Add Ox for Improved Performance #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

jjmonsalveg
Copy link

@jjmonsalveg jjmonsalveg commented Dec 6, 2024

Summary

This PR introduces a significant performance improvement by refactoring the EasySax.parser implementation to use ox as the underlying parser instead of Nokogiri.

The new ox_parser method is fully backward compatible with the current parser implementation, ensuring no breaking changes for existing users.

Note

While working on the EasyBroker challenge, I realized that achieving good performance and efficient memory usage requires a deeper analysis of the current implementation.

Key Changes

  1. Added ox_parser as an alternative parser method.
  2. Improved performance benchmarks:
    • Time: ox_parser is ~52% faster than EasySax.parser using Nokogiri.
    • Memory: ox_parser reduces allocated memory by ~35% and cuts object allocations by ~52%.
  3. Updated documentation to highlight the new ox_parser method and performance results.

Benchmark Results

Environment:

  • OS: macOS Sequoia 15.1.1 arm64
  • Hardware: MacBook Pro (14-inch, 2021), Apple M1 Pro, 32GB Memory
  • Ruby: 3.3.6 (2024-11-05 revision 75015d4c1f)

Results:

Time Benchmark:
                 user     system      total        real
Nokogiri:    0.000114   0.000015   0.000129 (  0.000128)
Ox:          0.000058   0.000002   0.000060 (  0.000062)

Memory Benchmark:
Nokogiri Parser:
Total allocated memory: 22.90625 KB
Total retained memory:  0.0 KB
Total objects allocated: 430
Total objects retained:  0

Ox Parser:
Total allocated memory: 14.984375 KB
Total retained memory:  0.078125 KB
Total objects allocated: 205
Total objects retained:  2

Changelog

New Features

  • Add new OxParser:
    • Introduced ox_parser for faster and more memory-efficient XML parsing, while maintaining backward compatibility with EasySax.parser.

Enhancements

  • Benchmark Tests:
    • Added memory and time benchmarks to compare performance between Nokogiri and Ox parsers.
  • Refactor Tests:
    • Updated test cases to support ox_parser.

Documentation

  • Update README:
    • Documented the ox_parser method and its performance benefits.
    • Reorganized README for better readability (80-character wrapping).

Code Quality

  • Run RuboCop:
    • Applied RuboCop to ensure code style and consistency.

Dependency Updates

  • Add Ox:
    • Added Ox as a dependency in the Gemfile for improved performance.
  • Ignore RVM Config:
    • Updated .gitignore to exclude .ruby-gemset and .ruby-version files.

@jjmonsalveg jjmonsalveg changed the title Refactor: Add Ox for Improved Performance Feature: Add Ox for Improved Performance Dec 6, 2024
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