Rendering & Light

Performance Guide

Tune CPU cost, solid-face count, contour complexity, shadow work, and TradingView drawing budgets in a predictable order.

Updated Publisher Alien_AlgorithmsPine Script v6

Performance tuning order

  • Lower occlusion resolution: try occlusionRaster = 384 before disabling occlusion.
  • Reduce maxFaces: cap the solid-face pool.
  • Reduce contour levels: fewer bands mean fewer projected paths.
  • Simplify primitives: lower sphere, cylinder, and torus segment counts.
  • Gate rendering: perform frame work inside barstate.islast.

Structural optimizations

  • Build geometry once and use updateSurface(), updateBars(), and transform methods.
  • Use mergeMeshes(..., removeInterior = true) for voxel-like structures.
  • Prefer directional lighting for shadow-heavy scenes.
  • Hide unneeded overlays rather than rebuilding scene arrays.
  • Use the linefill backend for new solid-face scenes.

Automatic and manual caches

Pine3D caches world vertices, camera projections, face preprocessing, shadow grids, and contour geometry. Public transform and update methods invalidate the right caches automatically.

Direct mutation needs explicit invalidation
After editing raw mesh vertices, call mesh.invalidateCache(). Use scene.invalidateAllCaches() after broad low-level edits.

Monitor drawing budgets

TradingView can drop excess drawings without an error. A table makes silent overruns visible because render does not clear tables.

Live drawing monitorpine
var table stats = table.new(position.bottom_right, 3, 2, bgcolor = color.new(#000000, 30))
table.cell(stats, 0, 0, "Polyline", text_color = color.white)
table.cell(stats, 1, 0, "Line", text_color = color.white)
table.cell(stats, 2, 0, "Label", text_color = color.white)
table.cell(stats, 0, 1, str.tostring(polyline.all.size()) + " / 100", text_color = color.white)
table.cell(stats, 1, 1, str.tostring(line.all.size()) + " / 500", text_color = color.white)
table.cell(stats, 2, 1, str.tostring(label.all.size()) + " / 500", text_color = color.white)

Positioning the viewport

scene.guiShift moves the scene horizontally into future or past time space. scene.yOffset shifts it vertically in price units.

Time coordinates

Pine3D drawings use xloc.bar_time, which allows distant horizontal placement without forcing Pine to extend a bar-index history buffer.

Pine3D is a graphical rendering library for Pine Script. TradingView drawing, execution, and publication limits still apply. © Alien_Algorithms.