Skip to content

New Marshal functions for VAST and VMAP#11

Merged
Lunkers merged 1 commit intoEyevinn:mainfrom
CarlLindqvist:marshal-vast-vmap
Apr 16, 2026
Merged

New Marshal functions for VAST and VMAP#11
Lunkers merged 1 commit intoEyevinn:mainfrom
CarlLindqvist:marshal-vast-vmap

Conversation

@CarlLindqvist
Copy link
Copy Markdown
Contributor

@CarlLindqvist CarlLindqvist commented Apr 15, 2026

VMAP marshaling (testVmap.xml — 3 ad breaks with full VAST):

ns/op B/op allocs/op
xml.Marshal ~218,000 205,002 994
MarshalVmap ~57,500 150,144 6
Speedup ~3.8x faster 27% less memory 99.4% fewer allocs

VAST marshaling (testVast.xml — 2 ads with full creatives):

ns/op B/op allocs/op
xml.Marshal ~22,500 24,936 115
MarshalVast ~3,930 5,376 1
Speedup ~5.7x faster 78% less memory 99.1% fewer allocs

Approach

The encoder in encoder_fast.go avoids all reflection by writing directly to a []byte buffer with append. Key optimizations:

  • No reflection — hardcoded struct field traversal matching xml.Marshal field order
  • Single allocation — one pre-allocated buffer, grown as needed (1 alloc for VAST, 6 for VMAP due to buffer regrowth)
  • Inline Duration/TimeOffset formatting — avoids fmt.Sprintf and strings.Builder allocations
  • Chunk-based entity encoding — copies runs of safe bytes at once rather than byte-by-byte

Use instead of xml.Marshal for better performance
Copy link
Copy Markdown
Collaborator

@Lunkers Lunkers left a comment

Choose a reason for hiding this comment

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

LGTM

@Lunkers Lunkers merged commit 4cca51e into Eyevinn:main Apr 16, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants