Comments (9)
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.
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.
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.
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.
hey giates, could you please check
http://github.com/apotonick/cells/commit/f9f3eb24cd6152005840e07a3dc861e5d8e78964
from cells.
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.
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.
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.
update: before my patch i had in
development mode
800ms
production mode
3000ms
now in production mode:
~50ms
from cells.
Related Issues (20)
- Cells + Airbrake issue - double exceptions raised HOT 2
- Using Cells with Rails engine that has html.erb partials not being picked up HOT 5
- Confusing file structure - views or view? HOT 7
- Template Missing ... again! HOT 21
- how to render erb templates when haml/hamlit and erb extensions installed HOT 3
- Render an array inside view cell HOT 1
- Escaping implementation seems to be a glaring LAYER VIOLATION, methinks.
- Is there some way to do html escaping default with options?
- Publish latest version on Rubygems HOT 10
- should default to file_name.html.erb or .haml HOT 1
- Can't get form_with to work from a cell in Rails 6 HOT 3
- License HOT 1
- Form Input renders as raw text in cell HOT 1
- Feature Request: Support Recyclable Cache Key
- Still maintained? Documentation URLs broken. HOT 9
- Default cache key produces clashes HOT 4
- Options hash is same instance passed to each cell when using collections HOT 1
- Slim v5 breaks cells HOT 9
- Ruby 3.0 ArgumentError: wrong number of arguments error with keyword args for Cell::Testing
- Ruby 3.0 ArgumentError: wrong number of arguments error with Caching
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cells.