Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby performance distilled, com Hanneli Tavante

273 views

Published on

Hanneli (a.k.a @hannelita) é uma desenvolvedora fissurada por programar, aprender novas linguagens, frameworks, explodir capacitores, programar em C pra relaxar e comitar código útil (ou não) em projetos Open Source aleatórios que encontra vasculhando Githubs alheios. Ela também gosta de café, especialmente os do Starbucks. Neste 7Masters Ruby, ela apresentou a talk "Ruby performance distilled".

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Ruby performance distilled, com Hanneli Tavante

  1. 1. Ruby performance distilled
  2. 2. Hi! I’m Hanneli
  3. 3. No advanced stuff Fast snippets You can agree or not
  4. 4. Why speed? ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)
  5. 5. Optimize makes my code uglier ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°) ( ͡° ͜ʖ ͡°)
  6. 6. Optimize makes my code uglier
  7. 7. IoT 128GB RAM at Amazon 1GB RAM at Raspberry
  8. 8. There are several layers to optimise Source code optimisation { Search time Sorting time Complexity Data Structures
  9. 9. Example #1 - counting Loops are very common for Hardware (1…65536).map { |i| i.to_s } (1…65536).map { &:to_s }
  10. 10. Example #2 - merge Hashes happen a lot in Hardware merge! merge
  11. 11. Example #3 - sub/gsub Substitutions (that occur only once) happen in Hardware “AD1”.gsub(“AD”, “DA") “AD1”.sub(“AD”, “DA")
  12. 12. Example #4 - permute Permutation happens in Hardware array.permutation home made solution
  13. 13. Example #4 - permute Permutation happens in Hardware else { /* this is the general case */ volatile VALUE t0; long *p = (long*)ALLOCV(t0, r*sizeof(long)+n*sizeof(char)); char *used = (char*)(p + r); VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */ RBASIC_CLEAR_CLASS(ary0); MEMZERO(used, char, n); /* initialize array */ permute0(n, r, p, used, ary0); /* compute and yield permutations */ ALLOCV_END(t0); RBASIC_SET_CLASS_RAW(ary0, rb_cArray); } return ary; RECURSIVE STUFF AAAAAAA
  14. 14. Example #5 - reverse reverse happens A LOT in Hardware reverse reverse! other
  15. 15. Example #5 - reverse reverse happens A LOT in Hardware static VALUE rb_ary_reverse_m(VALUE ary) { long len = RARRAY_LEN(ary); VALUE dup = rb_ary_new2(len); if (len > 0) { const VALUE *p1 = RARRAY_CONST_PTR(ary); VALUE *p2 = (VALUE *)RARRAY_CONST_PTR(dup) + len - 1; do *p2-- = *p1++; while (--len > 0); } ARY_SET_LEN(dup, RARRAY_LEN(ary)); return dup; } ༼ つ ◕_◕ ༽つ༼ つ ◕_◕ ༽つ
  16. 16. References • https://vimeo.com/114848080 • http://chriscontinanza.com/2010/10/29/Array.html • http://www.cse.dmu.ac.uk/~hgs/ruby/performance/ • https://www.youtube.com/watch?v=fGFM_UrSp70
  17. 17. Thanks!! Questions? @hannelita hannelita@gmail.com

×