Skip to content

Feature: Cache HTML templates in memory to optimize serveHtml performance #243

Description

@Yashaswini-K-P

Description

Currently, the serveHtml function reads HTML files from the disk on every incoming request using fs.readFile. While fs.readFile is asynchronous, reading from the disk repeatedly for static templates introduces unnecessary I/O overhead under heavy traffic. Since our frontend pages only change during a new deployment, we can optimize server efficiency by caching the file contents in memory after the first read.

Why this is Safe and Efficient

  • Efficient RAM Utilization: The template is stored exactly once in the central server's RAM. Whether 1 user or 1,000 users connect, memory usage does not multiply because they all read from the same cached reference.
  • Preserved Security: The security nonces (__NONCE__) will remain completely dynamic and unique per user request because the string replacement operation will still occur on the cached template in real-time on every request.

Expected Behavior

  • Drastic Reduction in Disk I/O: Bypasses filesystem operations completely for subsequent route requests (/', /leaderboard`, etc.).
  • Improved TTFB (Time to First Byte): Faster server response times under concurrent user loads.

Please assign this issue to me!

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions