Update floatreftarget.lua#14620
Conversation
Working around using ut8.codepoint since that was causing a stack overflow with rather large tables
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Thanks for the PR, but we're going to need more information than that to be able to accept it, especially if it's in a performance-sensitive setting. |
|
When I was rendering a document with some large tables I ran into this error:
Enumerating over the codepoints with utf8.codes instead of passing the whole big string to ut8.codepoint seemed like a reasonable workaround. But, I couldn't say if that is worse for performance. |
|
How big is that table? |
|
177 x 32. It isn't really readable for other reasons, just didn't expect it to crash the renderer. |
|
I had a look with claude to this problem, as I am no Lua performance expert. Here is the findings. The direction seems right: I can reproduce it. The trigger is the byte length of the slice, not the codepoint count — it overflows around Reproduction (run with
|
|
Actually I managed to build a self-contained reproduction. A 177×32 table (matching your dimensions) with dense cells generates a ~1 MB longtable and crashes on main: ---
format: pdf
keep-tex: true
---
```{r}
#| label: tbl-big
#| echo: false
#| tbl-cap: "A large table"
pad <- strrep("lorem ipsum dolor sit amet consectetur ", 10)
df <- as.data.frame(matrix(
substr(paste0("cell-", pad), 1, 180), 177, 32
))
knitr::kable(df, format = "latex", longtable = TRUE)
```On main this fails with the same error you saw: With this PR it renders cleanly (the generated .tex is ~1 MB). For what it's worth, the crash only hits tables emitted as raw LaTeX longtable since plain markdown tables go through a different path. That also gives us a basis for the regression test. |
|
I can update the PR to use index assignment to speed things up. (I'm on Pacific time, sorry about the wait) |
Speed things up using index assignment instead of table.insert
Description
Working around using ut8.codepoint in split_longtable_start since that was causing a stack overflow with rather large tables.
Checklist
I have (if applicable):