Posted by catch on November 7, 2009 at 7:05am
4 followers
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | filter.module |
| Category: | bug report |
| Priority: | critical |
| Assigned: | sun |
| Status: | closed (fixed) |
| Issue tags: | Performance |
Issue Summary
When listing formats - i.e. a comment form on node view, we do an individual query for each format. Attached patch stops that by building the array of filters the first time we call the function, so that subsequent calls only fetch from static instead. Needs some cleanup since variable naming gets a bit tangly in there, but removes two queries on a default 'article' view in HEAD.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| filters.patch | 2.85 KB | Idle | Failed: 14709 passes, 12 fails, 0 exceptions | View details |
Comments
#1
The last submitted patch failed testing.
#2
New patch, fixed tests, added caching for the query, avoids doing the extra work on the filters up front in case they don't actually get used.
HEAD:
Executed 72 queries in 45.77 milliseconds.
Patch:
Executed 70 queries in 46.68 milliseconds
#3
And the patch. I'm not sure why we call filter_list_formats() with an id of 0 on admin/config/content/filter/add, for now added a line to protect against this, not ideal but maybe sun can take a look?
#4
So, we reduced the number of queries, but we actually got slower?
#5
subscribing
I need to think about this edge-case.
#6
@Dries, devel query timings has something like a 50-100% standard deviation and isn't to be trusted unless it's dozens of queries or a huge filesort or something - page execution time is similarly unreliable, so those pastes are only for the query count (which is reliable as long as you have a warm cache).
It's also likely that benchmarks won't be conclusive with just these couple of queries, although I'm happy to run them.
The reason I post these patches is because:
* Less round trips to the database and less PHP overhead executing queries is worth having even when the queries themselves are small and indexed.
* 2-3 queries quickly adds up when it's multiplied across multiple issues and subsystems.
#7
+++ modules/filter/filter.module 1 Dec 2009 02:21:09 -0000@@ -556,15 +556,18 @@ function filter_list_format($format_id)
+ // filter_list_format() is called with the non-existing $filter_id of 0 when
+ // creating a new filter. When that occurs, return an empty array.
+ $result = isset($filters['all'][$format_id]) ? $filters['all'][$format_id] : array();
Whatever we do, we want to remove this condition.
Actually, I think that invoking filter_list_format() for new formats is totally wrong, so this bears a fix elsewhere, which we may want to include here, not sure.
#8
In this case, devel was accurate, because I was missing an index change on the {filter} table, leading to a 10ms query, whoops!
Thought of a benchmarking scenario, not the most realistic in the world but not impossible either.
I added a bunch of input formats so that were 15 enabled on the site, gave anonymous user access to 14, access to and view comments, then benchmarked node/1 ab -c1 -n1000
HEAD:
Requests per second: 9.83 [#/sec]
Executed 65 queries in 36.52 milliseconds.
With patch:
Requests per second: 10.51 [#/sec]
Executed 52 queries in 23.04 milliseconds.
I don't know any sites with 14 input formats, but I do know some with 6 or more. So that 7% change probably equates to 2-3% on a more realistic site.
We still need to resolve the admin/config/content/filter issue though per #7.
#9
I need to see what breaks.
#10
The last submitted patch failed testing.
#11
Here we go.
#12
The last submitted patch failed testing.
#13
Looks fine.
Index didn't make it into any of the patches, properly added this time.
Same benchmark as above, this time with 5 formats.
HEAD: 8.80 [#/sec]
Patch: 9.10 [#/sec]
#14
This patch nicely exposes a bug I already encountered in #394466-28: Full HTML description on node form is not descriptive enough, but didn't create an issue for yet.
filter_format_save() needs to save all available filters for a text format, regardless of their status.
This patch should hopefully fix it.
#15
Cross-posted with the bot.
#16
cross-posted. Merged in that index change.
#17
And with sun. This patch merges #13 and #14.
#18
omg. Either of those two should be fine :p
#19
LOL :)
Nope, yours uses a strange update function number :P
Let's hope that tests pass on #16 and be done with it :)
#20
The last submitted patch failed testing.
#21
Just ran #16 locally and it has the same failures.
#22
ok, that was quite a challenge. I'm totally happy that we have *so extensive tests* for filter.module. Changing this code lead to subsequent different fails in filter tests, which is awesome.
#23
The last submitted patch failed testing.
#24
oh nice, this also requires us to finally fix the installer. :)
#25
The last submitted patch failed testing.
#26
Also fixing PHP module's raw data query insertions...
#27
#28
The last submitted patch failed testing.
#29
#30
The last submitted patch failed testing.
#31
#32
The last submitted patch failed testing.
#33
Holy cow!
This turned into a true bugfest.
#34
erm, considering all the filter system and installation profile bugs that are fixed in this patch, bumping to critical.
#35
The last submitted patch failed testing.
#36
Thanks, catch! You saved us from monster post-release headaches!
#37
I spent some time looking at this and it looks good. The latest patch doesn't seem to apply though, and might need a quick reroll. Otherwise RTBC, IMO.
#38
Re-rolled against HEAD.
Also, to summarize these changes:
#39
Note that some of the critical issues I mentioned in the summary would not exist with #573852: Rename {filter_format}.name to .title and replace .format with machine-readable .name - i.e. if modules and tests were able to refer to text format "php_code" or "filtered_html" instead of MAX(format) or 1. But unfortunately, that's way too much for D7, because it would require us to change all 'format' columns throughout core, and on top of that, it would conflict with my plans for D8. :-(
Erm, so this was just FYI. ;)
#40
Looks fine here, Dries already reviewed, let's get this in before it reaches 40k ;)
#41
Committed to CVS HEAD. Great job.
#42
Automatically closed -- issue fixed for 2 weeks with no activity.