Permalink
Browse files

I SMELL SLOW

  • Loading branch information...
0 parents commit a9b71b25ae2449ed62f19894471eea74704998ad @mislav committed Sep 6, 2011
@@ -0,0 +1 @@
+tmp
@@ -0,0 +1,8 @@
+source :rubygems
+
+gem 'activesupport'
+gem 'sass-rails', '~> 3.1.0'
+gem 'coffee-rails', '~> 3.1.0'
+gem 'uglifier'
+gem 'compass', '~> 0.12.alpha'
+gem 'ruby-prof'
@@ -0,0 +1,86 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ bcrypt-ruby (3.0.0)
+ builder (3.0.0)
+ chunky_png (1.2.1)
+ coffee-rails (3.1.0)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0.rc1)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.2)
+ compass (0.12.alpha.0)
+ chunky_png (~> 1.2)
+ fssm (>= 0.2.7)
+ sass (~> 3.1)
+ erubis (2.7.0)
+ execjs (1.2.4)
+ multi_json (~> 1.0)
+ fssm (0.2.7)
+ hike (1.2.1)
+ i18n (0.6.0)
+ multi_json (1.0.1)
+ rack (1.3.2)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2)
+ rdoc (3.9.4)
+ ruby-prof (0.10.8)
+ sass (3.1.7)
+ sass-rails (3.1.0)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (2.0.0)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (!= 1.3.0, ~> 1.1)
+ thor (0.14.6)
+ tilt (1.3.3)
+ uglifier (0.5.2)
+ execjs (>= 0.3.0)
+ multi_json
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport
+ coffee-rails (~> 3.1.0)
+ compass (~> 0.12.alpha)
+ ruby-prof
+ sass-rails (~> 3.1.0)
+ uglifier
@@ -0,0 +1,21 @@
+**Sprockets is slow to render Sass in Rails that has a reasonable number of @imports**. Trying to figure out why.
+
+Here I have taken out my project's assets and set up the "render.rb" script to manually bootstrap Sass, Compass and Sprockets to compare:
+
+1. Direct Sass rendering (no Sprockets)
+2. Sprockets rendering without its own cache
+3. Monkeypatched Sprockets rendering (experimenting)
+
+The results I'm getting are pretty consistent:
+
+~~~
+$ bundle exec ruby render.rb
+
+Rendering a changed stylesheet 20 times:
+ user system total real
+direct: 4.330000 0.260000 4.590000 ( 4.572378)
+sprockets: 11.250000 0.510000 11.760000 ( 11.751674)
+sprockets hacked: 7.230000 0.300000 7.530000 ( 7.510054)
+~~~
+
+Direct Sass is reasonably fast. Same stylesheet through Sprockets is twice as slow. Currently experimenting on optimizing it makes it closer to direct rendering, but not quite there yet.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
+$(document).delegate '.actions input[type=submit].watched', 'click', ->
+ $(this).closest('.actions').addClass('asking')
+ false
+
+$(document).delegate '.actions input[type=submit].watched', 'ajax:before', ->
+ false
+
+$(document).delegate '.actions .question a[href="#cancel"]', 'click', ->
+ $(this).blur().closest('.actions').removeClass('asking')
+ false
+
+$(document).delegate '.actions .button_to', 'ajax:success', (e, html) ->
+ replaceActions $(this).closest('.actions'), html
+
+$(document).delegate 'a.revert', 'ajax:success', (e, html) ->
+ replaceActions $(this).closest('.actions'), html
+
+# preserve the ".other-info" element while replacing ".actions"
+replaceActions = (element, content) ->
+ parent = element.parent()
+ element.replaceWith(content)
+ preserve = element.find('.js-preserve')
+ parent.find('.actions').eq(0).prepend preserve
@@ -0,0 +1,3 @@
+//= require zepto
+//= require ujs
+//= require_tree .
@@ -0,0 +1,43 @@
+# Emulates HTML5 "placeholder" and "autofocus" attributes.
+# from https://github.com/teambox/teambox/blob/master/app/javascripts/html5.js
+$ ->
+ return unless window.Modernizr
+
+ unless Modernizr.input.placeholder
+ inputs = $('input[placeholder], textarea[placeholder]')
+
+ emulatePlaceholder = (input) ->
+ val = input.val()
+ text = input.attr('placeholder')
+ if not val or val is text
+ input.val(text).addClass 'placeholder'
+
+ inputs.live 'focusin', ->
+ input = $(this)
+ if input.val() is input.attr('placeholder')
+ input.val('').removeClass 'placeholder'
+
+ inputs.live 'focusout', ->
+ emulatePlaceholder $(this)
+
+ # setup existing fields
+ inputs.each ->
+ emulatePlaceholder $(this)
+
+ $(document).delegate "form:has(#{inputs.selector})", 'submit', ->
+ $(this).find(inputs.selector).each ->
+ input = $(this)
+ input.val('') if input.val() is field.attr('placeholder')
+
+ # observe new forms inserted into document and setup fields inside
+ $(document).delegate 'form', 'DOMNodeInserted', (e) ->
+ el = $(this)
+ if el.is('form')
+ el.find(inputs.selector).each ->
+ emulatePlaceholder $(this)
+
+ unless Modernizr.input.autofocus
+ input = $('input[autofocus]').eq(0)
+ if input.size()
+ input.focus()
+ input.get(0).select()
@@ -0,0 +1,30 @@
+pagination = $('.pagination').eq(0)
+
+viewportOffset = (el) ->
+ el.offset().top - document.body.scrollTop
+
+if pagination.size()
+ page = parseInt(pagination.find('.current').text())
+ lastPage = parseInt(pagination.find('a:not(.next_page)').eq(-1).text())
+ url = window.location.toString()
+ container = $('ol.movies').eq(0)
+ loading = false
+ scrollElement = if Zepto.browser.webkit then document else window
+
+ $(scrollElement).bind 'scroll', ->
+ return if loading
+ viewportHeight = document.documentElement.clientHeight
+ paginationOffset = viewportOffset(pagination) - viewportHeight
+
+ if paginationOffset < viewportHeight/2
+ loading = true
+ $.ajax
+ method: 'get'
+ data:
+ page: ++page
+ success: (data) ->
+ container.append data
+ if page is lastPage
+ $(scrollElement).unbind 'scroll'
+ pagination.hide()
+ loading = false
@@ -0,0 +1,12 @@
+if 'createTouch' of document
+ ignore = /:hover\b/
+ try
+ for stylesheet in document.styleSheets
+ idxs = []
+ # detect hover rules
+ for rule, idx in stylesheet.cssRules
+ if rule.type is CSSRule.STYLE_RULE and ignore.test(rule.selectorText)
+ idxs.unshift idx
+
+ # delete hover rules
+ stylesheet.deleteRule idx for idx in idxs
@@ -0,0 +1,111 @@
+fire = (el, name, data) ->
+ event = $.Event(name)
+ el.trigger(event, data)
+ not event.defaultPrevented
+
+handleRemote = (element) ->
+ return unless fire(element, 'ajax:before')
+ if element.is('form')
+ method = element.attr('method')
+ url = element.attr('action')
+ data = element.serializeArray()
+ # memoized value from clicked submit button
+ element.data 'ujs:submit-button', (i, button) ->
+ data.push button if button
+ null
+ else
+ method = element.data('method')
+ url = element.attr('href')
+ data = element.data('params') || null
+
+ ajaxOptions =
+ type: method || 'GET'
+ data: data
+ headers:
+ Accept: '*/*;q=0.5, ' + $.ajaxSettings.accepts.script
+ beforeSend: (xhr, settings) ->
+ return fire(element, 'ajax:beforeSend', [xhr, settings])
+ success: (data, status, xhr) ->
+ element.trigger('ajax:success', [data, status, xhr])
+ complete: (xhr, status) ->
+ element.trigger('ajax:complete', [xhr, status])
+ error: (xhr, status, error) ->
+ element.trigger('ajax:error', [xhr, status, error])
+
+ ajaxOptions.url = url if url
+
+ token = $('meta[name="csrf-token"]').attr('content')
+ ajaxOptions.headers['X-CSRF-Token'] = token if token
+
+ $.ajax(ajaxOptions)
+
+handleMethod = (link) ->
+ href = link.attr('href')
+ method = link.data('method')
+ csrf_token = $('meta[name=csrf-token]').attr('content')
+ csrf_param = $('meta[name=csrf-param]').attr('content')
+ form = $("<form method='post' action='#{href}'></form>")
+ hidden = "<input name='_method' value='#{method}' type='hidden' />"
+
+ if csrf_param? and csrf_token?
+ hidden += "<input name='#{csrf_param}' value='#{csrf_token}' type='hidden' />"
+
+ form.hide().append(hidden).appendTo('body')
+ form.submit()
+
+disableSelector = 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]'
+enableSelector = 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled'
+
+disableFormElements = (form) ->
+ form.find(disableSelector).each ->
+ element = $(this)
+ method = if element.is('button') then 'html' else 'val'
+ element.data('enable-with', element[method]())
+ element[method](element.data('disable-with'))
+ element.attr('disabled', 'disabled')
+
+enableFormElements = (form) ->
+ form.find(enableSelector).each ->
+ element = $(this)
+ method = if element.is('button') then 'html' else 'val'
+ element[method](element.data('enable-with')) if element.data('enable-with')
+ element.removeAttr('disabled')
+
+allowAction = (element) ->
+ message = element.data('confirm')
+ not message or confirm(message)
+
+$(document).delegate 'form[data-remote]', 'submit', (e) ->
+ element = $(this)
+ handleRemote element if allowAction element
+ false
+
+$(document).delegate 'form:not([data-remote])', 'submit', (e) ->
+ disableFormElements $(this)
+
+$(document).delegate 'form', 'ajax:beforeSend', (e) ->
+ disableFormElements $(this) if this is e.target
+
+$(document).delegate 'form', 'ajax:complete', (e) ->
+ enableFormElements $(this) if this is e.target
+
+buttonSelector = 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])'
+
+$(document).delegate buttonSelector, 'click', ->
+ button = $(this)
+ name = button.attr('name')
+ data =
+ if name
+ name: name
+ value: button.val()
+
+ button.closest('form').data('ujs:submit-button', data)
+
+$(document).delegate 'a[data-remote], a[data-method]', 'click', (e) ->
+ element = $(this)
+ if allowAction element
+ if element.data('remote') isnt null
+ handleRemote element
+ else
+ handleMethod element
+ false
@@ -0,0 +1,19 @@
+@import "compass";
+
+$body-type:geneva, "bitstream vera sans", helvetica, arial, sans-serif;
+$heading-type:"american typewriter", georgia, serif;
+
+$body-color:#02303f;
+$default-text-shadow-color:rgba(gray, .3);
+
+$lightblue:#4A8A9F;
+$top-color-stop:#DEEAEE;
+$bottom-color-stop:#EFF4F6;
+$lightblue-border:#CEDFE5;
+
+@mixin link-icon {
+ a {
+ text-decoration: none;
+ span { text-decoration: underline; }
+ }
+}
@@ -0,0 +1,5 @@
+@import 'base';
+
+@import 'layout';
+@import 'movie';
+@import 'compare';
Oops, something went wrong.

0 comments on commit a9b71b2

Please sign in to comment.