1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Slightly simplify the lookup of data in Dict.{get, getAsync, has}

Note that `Dict.set` will only be called with values returned through `Parser.getObj`, and thus indirectly via `Lexer.getObj`. Since neither of those methods will ever return `undefined`, we can simply assert that that's the case when inserting data into the `Dict` and thus get rid of `in` checks when doing the data lookups.
In this case, since `Dict.set` is fairly hot, the patch utilizes an *inline check* and when necessary a direct call to `unreachable` to not affect performance of `gulp server/test` too much (rather than always just calling `assert`).

For very large and complex PDF files this will help performance *slightly*, since `Dict.{get, getAsync, has}` is called *a lot* during parsing in the worker.

This patch was tested using the PDF file from issue 2618, i.e. http://bugzilla-attachments.gnome.org/attachment.cgi?id=226471, with the following manifest file:
```
[
    {  "id": "issue2618",
       "file": "../web/pdfs/issue2618.pdf",
       "md5": "",
       "rounds": 250,
       "type": "eq"
    }
]
```

which gave the following results when comparing this patch against the `master` branch:
```
-- Grouped By browser, stat --
browser | stat         | Count | Baseline(ms) | Current(ms) | +/- |    %  | Result(P<.05)
------- | ------------ | ----- | ------------ | ----------- | --- | ----- | -------------
Firefox | Overall      |   250 |         2838 |        2820 | -18 | -0.65 |        faster
Firefox | Page Request |   250 |            1 |           2 |   0 | 11.92 |        slower
Firefox | Rendering    |   250 |         2837 |        2818 | -19 | -0.65 |        faster
```
This commit is contained in:
Jonas Jenwald 2020-01-31 11:39:48 +01:00
parent 25693c6b6d
commit 160cfc4084
3 changed files with 20 additions and 11 deletions

View file

@ -121,11 +121,13 @@ describe("primitives", function() {
checkInvalidKeyValues(dictWithSizeKey);
});
it("should return correct value for stored Size key with undefined value", function() {
var dict = new Dict();
dict.set("Size");
it("should not accept to set a key with an undefined value", function() {
const dict = new Dict();
expect(function() {
dict.set("Size");
}).toThrow(new Error('Dict.set: The "value" cannot be undefined.'));
expect(dict.has("Size")).toBeTruthy();
expect(dict.has("Size")).toBeFalsy();
checkInvalidKeyValues(dict);
});