Closed
Bug 1559988
Opened 5 years ago
Closed 5 years ago
Make extension hooks faster
Categories
(bugzilla.mozilla.org :: General, enhancement)
Tracking
()
RESOLVED
FIXED
People
(Reporter: dylan, Assigned: dylan)
References
Details
(Keywords: perf)
Attachments
(1 file)
Every hook is $NUMBER_OF_HOOKS calls to ->can()
.
Some hooks can be called thousands of times per request, or more.
This patch changes how Bugzilla::Hook works. After all extensions are
loaded, the list of packages is passed to Bugzilla::Hook::finalize,
which builds a cache that maps hook names to lists of functions.
Calling a hook is just simple iteration over that list, which is much
faster. In addition, unused hooks have virtually no cost.
Benchmarking
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm
index dbab0e5..9bc3f18 100644
--- a/extensions/BMO/Extension.pm
+++ b/extensions/BMO/Extension.pm
@@ -2805,6 +2805,10 @@ sub tf_search_operator_field_override {
}
}
+sub hello_world {
+ say "hello world";
+}
+
sub app_startup {
my ($self, $args) = @_;
my $app = $args->{app};
The runtime can be tested like so:
perl bugzilla.pl eval 'use ojo; n { Bugzilla::Hook::process("hello_world") } 20_000' >/dev/null
0.213981 wallclock secs ( 0.21 usr + 0.00 sys = 0.21 CPU) @ 95238.10/s (n=20000)
After this change:
perl bugzilla.pl eval 'use ojo; n { Bugzilla::Hook::process("hello_world") } 20_000' >/dev/null
0.0158732 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) @ 2000000.00/s (n=20000)
Assignee | ||
Comment 1•5 years ago
|
||
woot |
This is about 12 times faster.
Assignee | ||
Comment 2•5 years ago
|
||
Comment 3•5 years ago
|
||
Merged to master.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•