[Pkg-javascript-commits] [pdf.js] 11/246: Optimize Ref_toString().
David Prévot
taffit at moszumanska.debian.org
Sun Sep 7 15:36:20 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 856e1c600b5a5339af82b1f36d25281fe2dff57c
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date: Thu Jul 24 06:32:10 2014 -0700
Optimize Ref_toString().
I have a large PDF where this function is called 1.6 million times
during loading. Minimizing the string concatenations reduces the
cumulative allocations done by Firefox within this function from 113 MB
to 48 MB.
---
src/core/obj.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/core/obj.js b/src/core/obj.js
index 0762adc..98e7a17 100644
--- a/src/core/obj.js
+++ b/src/core/obj.js
@@ -220,7 +220,13 @@ var Ref = (function RefClosure() {
Ref.prototype = {
toString: function Ref_toString() {
- return 'R' + this.num + '.' + this.gen;
+ // This function is hot, so we make the string as compact as possible.
+ // |this.gen| is almost always zero, so we treat that case specially.
+ var str = this.num + 'R';
+ if (this.gen !== 0) {
+ str += this.gen;
+ }
+ return str;
}
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list