Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speeding up writing of pdf objects. #1123

Closed
u-fischer opened this issue Aug 6, 2022 · 0 comments
Closed

speeding up writing of pdf objects. #1123

u-fischer opened this issue Aug 6, 2022 · 0 comments
Assignees

Comments

@u-fischer
Copy link
Member

Currently before writing a named object to the pdf, the code has first to look up the type of the object. When many objects are written this gets very slow. I would suggest to add variants where the type can be given directly:

\DocumentMetadata{uncompress}

\documentclass{article}
\usepackage{l3benchmark}
\begin{document}
abc
\ExplSyntaxOn

\typeout{obj write}
\benchmark_once:n{\int_step_inline:nn {1000}{\pdf_object_new:nn {testA#1}{dict}}}
\benchmark_once:n{\int_step_inline:nn {1000}{\pdf_object_write:nn {testA#1}{/A/B}}}

\cs_new_protected:Npn \__pdf_backend_object_write_dict:nn #1#2  %pdftex version
  {
    \tex_immediate:D \tex_pdfobj:D
      useobjnum ~
      \int_use:c
        { c__pdf_backend_object_ \tl_to_str:n {#1} _int }
        { << ~ \exp_not:n {#2} ~ >> } 
  }
  
\cs_new_protected:Npn \pdf_object_dict_write:nn #1#2 %#1name, #2 content
 {
   \__pdf_backend_object_write_dict:nn {#1}{#2}
 }  

\typeout{direct dict}  
\benchmark_once:n{\int_step_inline:nn {1000}{\pdf_object_new:nn {testB#1}{dict}}}  
\benchmark_once:n{\int_step_inline:nn {1000}{\pdf_object_dict_write:nn {testB#1}{/W/Z}}}
\ExplSyntaxOff

\end{document}
objwrite
0.212 seconds (1.01e6 ops)
2.2 seconds (1.05e7 ops)  %writing with lookup
directdict
0.744 seconds (3.63e6 ops)
0.004 seconds (1.91e4 ops) %writing without lookup
@josephwright josephwright self-assigned this Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants