enableCache property

bool enableCache
final

Whether to enable parsing cache for improved performance.

When enabled (default), parsed markdown AST is cached using an LRU cache. This significantly improves performance when:

  • The same markdown content is rendered multiple times
  • Widgets rebuild frequently (e.g., during list scrolling)
  • Multiple messages with identical content are displayed

Performance Impact:

  • Cache hit: ~0.1ms (vs ~15ms for re-parsing)
  • Memory overhead: ~50KB per cached entry
  • Recommended for list views and chat applications

Set to false if:

  • Content changes frequently (e.g., streaming updates)
  • Memory is extremely constrained
  • Each markdown text is unique and won't be reused

Example:

// Enable cache for static content in lists
SmoothMarkdown(
  data: message.content,
  enableCache: true, // default
)

// Disable for frequently changing content
SmoothMarkdown(
  data: liveEditingContent,
  enableCache: false,
)

See also: useRepaintBoundary for additional performance optimizations.

Implementation

final bool enableCache;