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

forkwell.com Y U SO SLOW

forkwell.com Y U SO SLOW

Forkwell Nite #2の発表スライド

Akira Matsuda

August 30, 2012
Tweet

More Decks by Akira Matsuda

Other Decks in Programming

Transcript

  1. % rails g ★ e.g. when Post has_many Comments ★

    % rails g model comment post:references body:text - indexed ★ % rails g migration add_user_id_to_comment user_id:integer - not indexed Monday, September 3, 12
  2. Asset Pipeline ★assets͸WEBαʔόʔͰ ★.scss => .css, .coffee => .js ΛϓϦ

    ίϯύΠϧ ★*.js, *.cssΛ1ϑΝΠϧʹ݁߹ Monday, September 3, 12
  3. slow query ★ ࠷ۙ୭͔ͷΞΫςΟϏςΟ͕͋ͬͨεΩϧλάͷ TOP 20-ish(20݅͝ͱʹϖʔδωʔγϣϯ) ★ ↑ͷͦΕͧΕͷεΩϧλά͝ͱʹ(ࣗ෼ͷ༑ͩͪͷ)୭ ͔͕௚ۙ7೔ؒҎ಺ʹߦͬͨΞΫςΟϏςΟͷ࠷৽6 ݅(ͨͩ͠ʮ+1͠·ͨ͠ʯͱʮಡΜͩΑʯ͸࠷৽ͷ΋

    ͷͷΈ)ʹ͍ͭͯɺ୭͕(FBʹొ࿥͞ΕͯΔݱࡏͷϩ έʔϧͷϑϧωʔϜ + ΞΠίϯը૾)ԿΛͲ͏͔ͨ͠ (I18nͭͭ͠)දࣔɻ7݅Ҏ্͋Δ৔߹͸ʮ΋ͬͱݟ ΔʯϘλϯΛදࣔɻ Monday, September 3, 12
  4. use vendor speci c SQL # -*- coding: utf-8 -*-

    class Activity < ActiveRecord::Base ... # ड͚औͬͨactivitiesΛɺpublication_idͷ஋͝ͱʹ࠷େ7݅ͣͭʹߜͬͯฦ͢ # [MySQLݶఆ] def self.select_top_7_per_publication_id(activities) # ࠷৽ͷ6+1݅(see moreΛදࣔ͢Δ͔Ͳ͏͔Λ൑ఆ͢ΔͨΊʹ׶͑ͯ1݅ଟΊʹऔಘ) Activity.from(<<-SQL).where("activities.row_number <= #{DISPLAY_ACTIVITY_NUM + 1}") (select *, if(@previous_publication_id <> publication_id, @rownum := 1, @rownum := @rownum + 1) as row_number, @previous_publication_id := publication_id from (#{activities.to_sql}) as a cross join (select @rownum := NULL, @previous_publication_id := 0) as r order by publication_id, id desc ) AS activities SQL end ... end ΩϞ͍ Monday, September 3, 12
  5. tools ★ PageSpeed (Google) ★ YSlow (Yahoo) ★ Chrome Developer

    Tools -> Audits ★ PageSpeed Insights https:// developers.google.com/speed/pagespeed/ insights ★ WEBPAGETEST http://www.webpagetest.org/ Monday, September 3, 12
  6. Defer parsing of JavaScript “Putting inline scripts after all other

    resources prevents blocking of other downloads, and it also enables progressive rendering.” https://developers.google.com/speed/ docs/best-practices/ rtt#PutStylesBeforeScripts Monday, September 3, 12
  7. CompassϠό͍؆୯͗ͯ͢Ϡό͍ ★ ର৅ը૾ϑΝΠϧΛద౰ͳσΟϨΫτϦʹ Ҡಈ % mkdir app/assets/images/icons % mv app/assets/images/{foo.png,bar.png,icons}

    ★ SCSS import "icons/*.png"; @include all-icons-sprites; ★ HTML = link_to ‘’, somewhere_path, class: 'icons-foo' Monday, September 3, 12
  8. Y current forkwell.com still slow? ★Assets ★social buttons & tracking

    ★શ෦ೖΓJS & શ෦ೖΓCSSͷฐ֐ ★ͦ΋ͦ΋τοϓϖʔδ͕ ͪ͝Όͪ͝Ό͗͢͠ Monday, September 3, 12