How to improve performance when using context in Header / Footer on Large Docs?

Hello! I have an application that can generate a PDF from data that the user inputs. There are some scenarios where the data inputted can result in very large docs (19,000 pages as one of the extremes). Does anyone actually look at that; probably not, but they need it for their records…

I’ve noticed when I upgraded to 0.13.1 and started using context in my header and footer when I set the page that I take a performance hit on these large documents. I’ve tested the following scenarios:

Header and Footer Set - 1 hour 9 min compile time
#set page(
  paper: "us-letter",
  margin: (
    x: 1.25cm,
    top: 2.75cm,
    bottom: 2cm,
  ),
  header: context {
    if counter(page).get().first() > 1 [
      Hello
    ]
  },
  footer: context {
    if counter(page).get().first() > 1 [
      #align(center, counter(page).display(("1")))
    ]
  }
)
Header Only Set - 30 min compile time
#set page(
  paper: "us-letter",
  margin: (
    x: 1.25cm,
    top: 2.75cm,
    bottom: 2cm,
  ),
  header: context {
    if counter(page).get().first() > 1 [
      Hello
    ]
  }
)
Footer Only Set - 29 min compile time
#set page(
  paper: "us-letter",
  margin: (
    x: 1.25cm,
    top: 2.75cm,
    bottom: 2cm,
  ),
  footer: context {
    if counter(page).get().first() > 1 [
      #align(center, counter(page).display(("1")))
    ]
  }
)
No Header / No Footer - 5 min compile time
#set page(
  paper: "us-letter",
  margin: (
    x: 1.25cm,
    top: 2.75cm,
    bottom: 2cm,
  ),
)
No Header / No Footer / Set Page Number - 16 min compile time
#set page(
  paper: "us-letter",
  margin: (
    x: 1.25cm,
    top: 2.75cm,
    bottom: 2cm,
  ),
)

// table of contents

#set page(numbering: "1")

#show outline: set text(var_paragraph_text_size)

#show outline.entry.where(
  level: 1
): it => {
  v(12pt, weak: true)
  strong(it)
}

#set heading(numbering: "1.")

#outline(
  indent: auto
)

#pagebreak()

I’m totally OK if this is the way it is since these docs are huge, but I figured I’d ask if there are any work arounds I could try where I could still have a header and footer but go about it a different way? I programmatically build out the typst file from the data inputted, so I have flexibility in how I can construct it.

Thanks!

This change is an exciting performance improvement for some documents, especially if you have a lot of repeated items: Faster constraint checking in comemo (bumps comemo & krilla) by laurmaedje · Pull Request #6683 · typst/typst · GitHub It’s in the development version (will be in Typst 0.14, whenever that arrives), so it could be worth checking if that’s an improvement for your document.

If you have a clear reproducing example that’s unnecessarily slow, then that’s a good basis for a bug report I think.

1 Like

I don’t know if I’d call it a bug, just a by product of these extremely large docs. But I’m excited to test out release 0.14 when it comes out to see if it helps in these scenarios.