spree/spree — pull request #5776 by mtomov (2014-12-13 23:41:21+00:00)
Title: Improve store performance for orders with total quantity > 1000

by refactoring Package#add and converting Package#contents to a Set

fixes #5706

```ruby

# Spree 3.0 latest

user system total real
1000 Inventory Units: 3.490000 0.060000 3.550000 ( 3.732619)
2000 Inventory Units: 10.760000 0.120000 10.880000 ( 11.182196)
3000 Inventory Units: 23.590000 0.210000 23.800000 ( 24.274458)

# commenting out Spree::Stock::Package#add -> #unless find_item(inventory_unit)
# (no comparison is performed)
user system total real
1000 Inventory Units: 1.910000 0.070000 1.980000 ( 2.165775)
2000 Inventory Units: 3.460000 0.130000 3.590000 ( 3.921917)
3000 Inventory Units: 5.400000 0.180000 5.580000 ( 6.061517)

# After converting Package.contents to a Set from Array
user system total real
1000 Inventory Units: 2.100000 0.070000 2.170000 ( 2.376794)
2000 Inventory Units: 3.700000 0.140000 3.840000 ( 4.187232)
3000 Inventory Units: 5.620000 0.200000 5.820000 ( 6.382836)

```

----
After the change, `#find_item` is only used by `#remove`. Please advise if `#remove` should also receive a better implementation.

Also note the slight change of comparison behaviour between `#find_item` and the `#eql?`.

Feedback is appreciated!