YorickPeterse/ffi-aspell — pull request #15 by schmich (2014-09-04 02:08:00+00:00)
Title: Improving performance by eliminating unnecessary speller creation and deletion

Previously, an internal speller object was created and destroyed for every call to `#correct?` and `#suggestions`. Now, an internal speller object is only allocated when the initial `FFI::Aspell::Speller` object is created and when its configuration changes.

This does make the API more complex since users now need to call `#close` (or use `#open`) to free the internal speller object, but the performance gains are significant. Using my little [wordament-solver](https://github.com/schmich/wordament-solver) project, I get the following performance numbers:

- 1,207,100 calls to `#correct?`
- Before fix
- `ruby -I../ffi-aspell/lib solver.rb 2118.34s user 320.91s system 98% cpu 41:24.01 total`
- 570 calls/s
- After fix
- `ruby -I../ffi-aspell/lib solver.rb 7.08s user 0.45s system 99% cpu 7.590 total`
- 170,494 calls/s

In other words, the runtime of the solver dropped from about 41 minutes down to 7 seconds (~327x improvement).

I've included updated documentation and README for `#open`, `#close`, and `#closed?` as well as 7 new tests.

This is a significant enough change to warrant discussion. These changes create a compatibility issue in the public API since existing users will now be effectively leaking the internal speller object. I would suggest possibly bumping the major version number to indicate backwards-incompatible changes (see [SemVer](http://semver.org/)).