Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tunando o seu código Ruby

Tunando o seu código Ruby

Palestra ministrada no RuPy Campinas 2015

Andre Luis Anastacio

June 20, 2015
Tweet

More Decks by Andre Luis Anastacio

Other Decks in Programming

Transcript

  1. Tunando o seu código Ruby

    View full-size slide

  2. André Luís
    @ndrluis

    View full-size slide

  3. VAMOS FALAR DE COISA BOA?

    View full-size slide

  4. RUBY É LENTO?

    View full-size slide

  5. RAILS É LENTO?

    View full-size slide

  6. TUNAR GC É NECESSARIO?

    View full-size slide

  7. http://helabs.com/blog/2014/12/19/ruby-gc-tuning-parameters/
    http://www.akitaonrails.com/2015/03/27/small-bites-novidades-no-
    garbage-collector-do-ruby-2-2-1#.VYTSx2DrdBU
    http://www.infoq.com/br/presentations/entendendo-garbage-
    collector-ruby

    View full-size slide

  8. APRENDA A MENSURAR

    View full-size slide

  9. https://github.com/schneems/derailed_benchmarks
    Richard Schneeman

    View full-size slide

  10. $ derailed bundle:mem
    TOP: 87.5938 mb
    carrierwave: 35.9023 mb
    carrierwave/storage: 27.2773 mb
    fog: 27.125 mb
    fog/joyent: 5.2266 mb
    fog/joyent/compute: 5.1641 mb
    net/ssh: 4.9297 mb
    net/ssh/transport/session: 2.5977 mb
    net/ssh/transport/algorithms: 1.7188 mb
    net/ssh/transport/kex: 0.4375 mb
    net/ssh/transport/hmac: 0.375 mb
    net/ssh/transport/packet_stream: 0.5078 mb
    net/ssh/authentication/session: 1.0508 mb
    net/ssh/authentication/key_manager: 0.5039 mb
    net/ssh/connection/session: 0.9531 mb
    net/ssh/connection/channel: 0.3203 mb

    View full-size slide

  11. refile/rails: 0.9688 mb
    refile: 0.9688 mb
    rest_client: 0.6367 mb
    /Users/…/lib/restclient: 0.6367 mb
    /Users/…/lib/restclient/abstract_response: 0.4844 mb
    http-cookie: 0.4844 mb
    http/cookie: 0.4805 mb
    domain_name: 0.3984 mb
    domain_name/etld_data: 0.3789 mb

    View full-size slide

  12. $ derailed bundle:objects
    allocated objects by gem
    -----------------------------------
    281 refile-0.5.5
    2499 carrierwave-0.10.0

    View full-size slide

  13. $ derailed bundle:mem
    TOP: 89.2617 mb
    activeadmin: 24.1797 mb
    active_admin: 24.1797 mb
    ransack: 6.9805 mb
    ransack/adapters/active_record: 3.0039 mb
    action_view/view_paths: 0.6992 mb
    action_view/base: 0.6328 mb
    ransack/search: 0.4063 mb
    action_dispatch/http/request: 0.3828 mb
    active_admin/batch_actions: 4.0039 mb

    View full-size slide

  14. Refile > Carrierwave
    RailsAdmin > ActiveAdmin

    View full-size slide

  15. NÃO NECESSARIAMENTE

    View full-size slide

  16. refile/rails: 2.3555 mb
    refile: 2.2539 mb
    rest_client: 1.7109 mb

    View full-size slide

  17. SABER MENSURAR É
    IMPORTANTE

    View full-size slide

  18. benchmark-ips
    https://github.com/evanphx/benchmark-ips

    View full-size slide

  19. slow 47524.3 (± 7.6%) i/s
    fast 56823.2 (± 7.2%) i/s
    20% mais rapido

    View full-size slide

  20. CUIDADO COM OPTIMIZAÇÃO
    PREMATURA!

    View full-size slide

  21. CRIE MENOS OBJETOS!

    View full-size slide