Coder Social home page Coder Social logo

Comments (9)

giates avatar giates commented on July 30, 2024

I just tried with new rails project:

script/generate cell test test test1
script/generate controller test test

app/views/test/test.html.erb:
<%- 1.upto(100) do -%><%= render_cell :test, :test %><%- end -%>

Now calling http://localhost:3000/test/test:

development: Completed in 722ms (View: 718, DB: 0)
production: Completed in 800ms (View: 799, DB: 0)

I don't understand where is the problem...

from cells.

giates avatar giates commented on July 30, 2024

I just tried reverting the test application from cells to partials:

app/views/test/test.html.erb:
<%- 1.upto(100) do -%><%= render :partial => "test" %><%- end -%>

app/views/test/_test.html.erb:

Test#test

development: Completed in 65ms (View: 61, DB: 0)
production: Completed in 24ms (View: 23, DB: 0)

The results are now correct: production is about 3x faster than development (cells seems to be 10x slower than partial but this is not a big problem, the problem is that in production mode cells are slower than development mode...)

from cells.

apotonick avatar apotonick commented on July 30, 2024

hi giates,
thanks for your interesting report. the only problem i can think of is that cells does NOT cache view paths in production mode, while it does cache it in development mode (may-be?). this would slow down rendering as it has to lookup views at every render call. i will investigate on that.
btw- great test case, thanks again ;-)

nick

from cells.

sjamaan avatar sjamaan commented on July 30, 2024

I noticed that if you use cell class hierarchies, it can be quite slow because it traverses the hierarchy to find the file every single time. Instead, you can cache it in the template class. Here's a patch for the Rails 2.1 version which I'm still using. I'm sure it is pretty trivial to port it to the latest version. (I hope this comes through correctly, there's no preview function...)

Index: lib/cell/template_finder.rb
===================================================================
--- lib/cell/template_finder.rb (revision 55)
+++ lib/cell/template_finder.rb (working copy)
@@ -39,13 +39,19 @@
     # First check for this template in the application. If it exists, the user has
     # overridden anything from the plugin, so use it (unless we're testing plugins).
     def resolve_cells_path_and_extension(cell, state, type_ext)
+      @@known_paths ||= {}
+      res = @@known_paths["#{cell.cell_name}/#{state}/#{type_ext}"]
+      return res if res
+
       resolve_cell = cell.class

       while resolve_cell != Cell::Base
         possible_cell_paths.each do |path|
           template_handler_extensions.each do |ext|
             if File.exists?(path_for_cell_template_with_type_extension(path, resolve_cell.cell_name, state, type_ext) +'.'+ext)
-              return [path_for_cell_template_with_type_extension(path, resolve_cell.cell_name, state, type_ext), ext]
+              res = [path_for_cell_template_with_type_extension(path, resolve_cell.cell_name, state, type_ext), ext]
+              @@known_paths["#{cell.cell_name}/#{state}/#{type_ext}"] = res if ENV["RAILS_ENV"] == "production"
+              return res
             end
           end
         end

from cells.

apotonick avatar apotonick commented on July 30, 2024

hey giates, could you please check
http://github.com/apotonick/cells/commit/f9f3eb24cd6152005840e07a3dc861e5d8e78964

from cells.

yury avatar yury commented on July 30, 2024

Still very slow on production with rails 2.3.x
if config.action_view.cache_template_loading == true (as in production) then
ActionView use EagerPath and with Cells it very slow.
if config.action_view.cache_template_loading == false then
ReloadablePath path is used in ActionView

from cells.

yury avatar yury commented on July 30, 2024

huge speed with http://github.com/yury/cells/commit/2096bae64198942beb7c55806ac933c67033d665

without fix:
Completed in 2995ms (View: 2855, DB: 84) | 200 OK
with fix:
Completed in 433ms (View: 263, DB: 84) | 200 OK

from cells.

cice avatar cice commented on July 30, 2024

hey guys,
the problem lies in here:
http://github.com/apotonick/cells/blob/master/lib/cell/base.rb#L220
self.view_paths = ActionView::PathSet.new

one would expect that self.view_paths now contains a PathSet, but due to the implementation of class_inheritable_array, it is still an array, therefore all caching,memoizing etc is repeated for every request (which is avoided with a pathset, cause every path is saved as EagerPath with a @loaded flag). if you pass an array to the template, every path gets parsed into an EagerPath, memoized and freezed with every request for each cell!

a simple solution would be to replace
self.view_paths = ActionView::PathSet.new
with
write_inheritable_attribute(:view_paths, ActionView::PathSet.new)

it took me about 5 hours to get to that, at least im now familiar with cells and rails source code :D

from cells.

cice avatar cice commented on July 30, 2024

update: before my patch i had in
development mode
800ms
production mode
3000ms

now in production mode:
~50ms

from cells.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.