title: Python: Why opening an XFA pdf file takes longer than a txt file of same size?
body: <p>I am currently developping some python code to extract data from 14 000 pdfs (7 Mb per pdf). They are dynamic XFAs made from Adobe LiveCycle Designer 11.0 so they contain streams that needs to be decoded later (so there are some non-ascii characters if it makes any difference).</p>
  <p>My problem is that calling open() on those files takes around 1 second each if not more.</p>
  <p>I tried the same operation on 13Mb text files created from copy-pasting a character and they take less than 0.01 sec to open. <strong>Where does this time increase come from when I am opening the dynamic pdfs with open()? Can I avoid this bottleneck?</strong></p>
  <p>I got those timings using cProfile like this:</p>
  <pre><code>from cProfile import Profile
  profiler = Profile()
  profiler.enable()
  f = open('test.pdf', 'rb')
  f.close()
  profiler.disable()
  profiler.print_stats('tottime')
  </code></pre>
  <p>The result of print_stats is the following for a given xfa pdf:
  <a href="https://i.stack.imgur.com/0hhzQ.png" rel="nofollow noreferrer">io.open() takes around 1 second to execute once</a></p>
  <p>Additionnal information:
  I have noticed that the opening time is around 10x faster when the same pdf file was opened in the last  15 or 30 minutes, even if I delete the <code>__pycache__</code> directory inside of my project. A solution that could make this speed increase apply regardless of the elapsed time could be worth it, though I only have 50 Gb left on my pc.
  Also, parallel processing of the pdfs is not an option since I only have 1 free core to run my implementation...</p>