Skip to content

perf(citation): optimize CITATION.cff rendering - #39575

Open
silverwind wants to merge 2 commits into
go-gitea:mainfrom
silverwind:cff-limits
Open

silverwind wants to merge 2 commits into
go-gitea:mainfrom
silverwind:cff-limits

Conversation

@silverwind

@silverwind silverwind commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Rendering a CITATION.cff could use memory far out of proportion to the file, as every YAML alias copies its target into the formatted citation and the parser copies %TAG prefixes into every node. Files past these limits show no citation, like unparseable ones do today.

  • Skip files over 256 KiB, largest real-world file found is 80 KiB
  • Skip files with %TAG directives
  • Skip files whose aliases add more than 64 Ki nodes and value bytes
  • Skip self-referencing anchors, except a sequence listing itself

Memory of one FormatCFF call:

Input Before After
68 KB with 1024 aliases 552-1636 MiB alloc 0
254 KB with %TAG 3.1 GB RSS 13 MB RSS
8 MiB, no aliases 2.1 GB RSS skipped

Rendering a CITATION.cff could use memory far out of proportion to the
file, as every YAML alias copies its target into the formatted citation
and the parser copies %TAG prefixes into every node. Skip files over
256 KiB, files with %TAG directives, and files whose aliases add more
than 64 Ki nodes and value bytes or reference their own anchor.

Assisted-by: Claude Code:claude-opus-5-5
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 4, 2026
Decoders never expand a sequence that lists itself, like
`license: &loop [*loop]`, so only reject other self-references, which
can decode their enclosing anchor once per reference.

Assisted-by: Claude Code:claude-opus-5-5
Comment thread modules/citation/cff.go
}

const (
maxFileSize = 256 * 1024 // parsing takes up to ~1000x the input

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limit is here

content, err := entry.Blob(ctx.Repo.GitRepo).GetBlobContent(ctx, setting.UI.MaxDisplayFileSize)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants