[ 
https://issues.apache.org/jira/browse/PDFBOX-5575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17702246#comment-17702246
 ] 

Tilman Hausherr commented on PDFBOX-5575:
-----------------------------------------

Re the direction, I had a look at the table and the lengths are mixed, i.e. the 
entry count goes up and down:
{noformat}
258: 2 [0, 0]
259: 3 [0, 0, 0]
260: 4 [0, 0, 0, 0]
261: 5 [0, 0, 0, 0, 0]
262: 6 [0, 0, 0, 0, 0, 0]
263: 7 [0, 0, 0, 0, 0, 0, 0]
264: 8 [0, 0, 0, 0, 0, 0, 0, 0]
265: 9 [0, 0, 0, 0, 0, 0, 0, 0, 0]
266: 10 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
267: 11 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
268: 12 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
269: 13 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
270: 14 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
271: 15 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
272: 16 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
273: 17 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
274: 18 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
275: 19 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
276: 20 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
277: 21 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
278: 22 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
279: 23 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
280: 18 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]
281: 2 [-1, -28]
282: 2 [-28, -36]
283: 2 [-36, -1]
284: 3 [-1, -28, -36]
285: 3 [-36, -1, -28]
286: 3 [-28, -36, -1]
287: 4 [-1, -28, -36, -1]
288: 5 [-1, -28, -36, -1, -28]
289: 3 [-28, -36, 0]
290: 24 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
291: 17 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]
292: 6 [-1, -28, -36, -1, -28, -36]
293: 2 [-36, 0]
294: 25 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0]
295: 26 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0]
296: 6 [0, 0, 0, 0, 0, -1]
297: 7 [-1, -28, -36, -1, -28, -36, 0] {noformat}
So I agree that the direction doesn't matter. However what does matter is that 
the new code leaves the loop as soon as it finds a match. The old code tries to 
get the longest match. (I have no idea why the encodings with the new code 
aren't longer)

> optimize LZWFilter
> ------------------
>
>                 Key: PDFBOX-5575
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5575
>             Project: PDFBox
>          Issue Type: Improvement
>    Affects Versions: 3.0.0 PDFBox
>            Reporter: Axel Howind
>            Priority: Minor
>         Attachments: optimize_LZWFilter.patch
>
>
> I ran the PDFBox tests with a profiler and saw that LZWFilter used quite a 
> bunch of time, so I thought I might look at the code. I just looked at it 
> totally out of context and tried to understand what is done there and what 
> could be changed without altering results.
>  * made the private mehtods static
>  * changed the variable/method parameter 'earlyChange' from integer to 
> boolean because I thought tha would be more readable
>  * some minor tweaks
>  * it looks like codeTable is initialized quite often and everytime, 256 
> length 1 byte arrays are created, so I pre-allocate those byte arrays so that 
> they can be shared by all code tables. [~tilman] I assumed the contents of 
> the codeTable entries will not be changed, and my analysis of the code seems 
> to prove that (also the passing unit tests). Just please have a look at this 
> so I don't break anything.
>  * it took me some time to fully understand what findPatternCode() does and 
> why it checks the codeTable in reverse order. I more or less recreated that 
> method from scratch and I think it should now always be faster: for patterns 
> of length 1 no iteration is done, and for longer patterns iteration stops 
> once the correct entry is found. As this is the most notable change, please 
> take a closer look. Unit tests pass.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to