Issue #5968: refactor canvas renderer for performance.

Refactor canvas renderer for performance.