Comments

killes@www.drop.org’s picture

StatusFileSize
new1.91 KB

Here is the patch. It slao make calling node_load without specifying node->nid unwise. Only poll.module needs to be fixed.

killes@www.drop.org’s picture

That's a patch. The patch works well at my site. A patch for poll.module is forthcoming.

killes@www.drop.org’s picture

StatusFileSize
new2.28 KB

Here is an improved atch which does obliterate the patch to poll.module. Calling node_load without specifying node->nid is still safe.

dries’s picture

Do you have performance numbers?

killes@www.drop.org’s picture

The first attachement to this task. There seems to be still a problem with viewing polls. Needs investigation. This patch is very helpfull if you use many node types that use the _load hook (flexinode, event, ...).

killes@www.drop.org’s picture

The problem with poll.module is that its load hook's action depends on the uid of the user. This is legitimate use I guess. Anybody got an idea on how to work around that?

killes@www.drop.org’s picture

Upon reading some poll.module code, I think that we could move the user specific part to poll_view. Opinions?

killes@www.drop.org’s picture

Steven and I had a second look at the patch. As a result, revisions aren't cached anymore (they don't appear on node listings anyway) and bootstrap.inc doesn't need patching anymore.

killes@www.drop.org’s picture

StatusFileSize
new1.75 KB

Steven and I had a second look at the patch. As a result, revisions aren't cached anymore (they don't appear on node listings anyway) and bootstrap.inc doesn't need patching anymore.

Steven’s picture

StatusFileSize
new3.1 KB

Here is a current patch for the poll.module which moves the user-specific checks out of hook_load().

Steven’s picture

StatusFileSize
new2.93 KB

Keeping poll patch current.

killes@www.drop.org’s picture

Both patches apply again. I want to stress that this patch is important to avoid several popular contrib modules (flexinode, event) becoming "site killers" by using the nodeapie "load" hook.

killes@www.drop.org’s picture

StatusFileSize
new1.85 KB

I've extended the patch to store the $node object in a static var. This fixes http://drupal.org/node/view/10145

killes@www.drop.org’s picture

StatusFileSize
new2.24 KB

The book module needs a patch too.

It does the following:

It removes book_load. Treating nodes differently depending on if they are native book nodes or not makes no sense and is confusing for the user. This part of the codes was broken anyway.

It moves the query done in _nodeapi('view') to 'load' to take advantage of caching.

killes@www.drop.org’s picture

StatusFileSize
new1.98 KB

The static var didn't make too much sense.

dries’s picture

The book module change will result in extra database overhead because it is executed for each load. Secondly, mind to explain why the current code is broken?

killes@www.drop.org’s picture

The load will be executed only once and with my node object caching the result will be stored in the cache.

The current code is broken do to

if (arg(1) == 'edit' && !user_access('administer nodes')) {
^

dries’s picture

But if a call to node_load() turns out not to be non-cacheable, you'll pay the extra overhead. You are (incorrectly) assuming that the caching will always kick in.

Also, it is unclear whether the poll module patch is still required. Can you make a single patch with all required changes?

killes@www.drop.org’s picture

StatusFileSize
new7.29 KB

Ok, here is an updated patch. It includes both the poll and the book patch. There is a small change from the previous patch: Only the last loaded node is cached in a static var. Otherwise the memory consumption would maybe have gone through the roof for a node/ page where the nodes have a lot of revisions.

I will provide new performance numbers shortly. I also believe that in most cases the cache _will_ kick in.

killes@www.drop.org’s picture

Without this patch:
754ms +- 16.2 for /node, 43 queries in total, 2 polls, 8 other.

With patch:
725ms +- 5.3 for /node, 36 queries in total, 2 polls, 8 other.

The "other" node types have a query in nodeapi('load') like many have (forum, ...)

The patched version is faster by 4%.

Another run with 2 polls, 7 other, and one flexinode node with four fields:

With patch:

761ms +- 2.5, 39 queries

Without patch:

797ms +- 3, 49 queries

4% again.

2 polls, 6 other, 2 flexinodes

With
762ms +- 6.0, 39 queries

without
798ms +- 5.6, 50 queries

4.5%

While this 4.x% improvement may look insignificant to some, it is a good improvement if a lot of registered users keep coming back to your front page. Other pages will also benefit (all the ones that call node_load). Also, the cost is only one entry in the cache table per node.

Steven’s picture

The "keep last node" part of this patch is interesting because on several pages, we do repeated node_loads for the same node, in succession:
- node.module, hook_menu: determine whether or not to show the edit and revisions tab
- node.module, when viewing a node
- poll.module, hook_menu: determine whether or not to show the poll results tab.

Also, someone might run a block which kicks in for node/id and displays extra info on the side. Such a block can now re-use the node object without having to query the db again and call hook_load/nodeapi('load').

Anonymous’s picture

If for nothing else, for the "keep the last node" part, this patch is worth applying!

killes@www.drop.org’s picture

StatusFileSize
new1.54 KB

Here is an updated and simplified version of that patch. It will no longer store info in the DB but only use a static var.

dries’s picture

I tried the static/simple node caching patch with the Forum topics' and 'Book navigation' blocks enabled.

I get a 9% speedup for forum topics, and a 1% speedup for book pages. The patch eliminates 12 queries for the forum topic page, and 8 queries for the book page. On the forum page, there are no duplicate queries left. The main page is unaffected.

dries’s picture

Committed to HEAD. Thanks.

Anonymous’s picture