Skip to content

issue 34046 velocity memory & sync issues#34050

Open
wezell wants to merge 17 commits intomainfrom
issue-34046-velocity-memory-sync-issues
Open

issue 34046 velocity memory & sync issues#34050
wezell wants to merge 17 commits intomainfrom
issue-34046-velocity-memory-sync-issues

Conversation

@wezell
Copy link
Contributor

@wezell wezell commented Dec 9, 2025

Summary

Reduces memory allocations and fixes synchronization issues in Velocity page rendering.

Memory Optimizations

  • ThreadLocal pools for StringBuilder, StringWriter, and arrays in hot paths
  • byte[] page cache instead of String to eliminate encoding roundtrips
  • Singleton viewtools to avoid repeated instantiation
  • Capacity-limited buffers to cap memory usage per thread

Sync Fixes

  • Striped locks with timeout in DotResourceLoader to prevent thundering herd
  • Avoid unnecessary session attribute writes that caused contention

Other

  • Fixed NPE in LanguageWebAPIImpl
  • Improved DotConcurrentFactoryTest runtime (~3s vs ~60-90s)

Files Changed

Area Key Files
Velocity Core VelocityUtil, VelocityLiveMode, DotResourceLoader, PageRenderUtil
Caching StaticPageCache, PageCacheParameters
Content ContentMap, StringifyObject
Filters CMSFilter, CMSUrlUtil, LanguageWebAPIImpl
Velocity Parser ASTMethod

Impact: ~90% reduction in temporary allocations for typical page renders.

Conversation link

https://dotcms.slack.com/archives/C04FRV45YR5/p1765222245235399

@wezell
Copy link
Contributor Author

wezell commented Dec 9, 2025

Sped up DotConcurrentFactoryTest

Key Optimizations

  1. Reduced sleep in PrintTask: 500ms → 20ms
  2. Reduced sleep in ConditionalSubmitter test: 8 seconds → 200ms
  3. Reduced iteration counts: Only as many as needed to verify behavior
  4. Eliminated busy-wait polling loops: Replaced with Future.get() awaits
  5. Used proper assertions: assertSame/assertNotSame instead of assertTrue/assertFalse
  6. Added proper shutdown: ExecutorService cleanup

Estimated Time Savings

Before After
~60-90 seconds ~2-3 seconds

@wezell wezell changed the title issue 34046 velocity memory sync issues issue 34046 velocity memory & sync issues Dec 9, 2025
@wezell wezell linked an issue Dec 9, 2025 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

fix(velocity): Memory and sync issues

1 participant