dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / webview / tests_webview_memory.lucb
#==============================================================================================
#
# tests_webview_memory - the memory census, and display lists that die when replaced
#
# DESCRIPTION:
# The census sees the heap's phases, and a page painted again and again keeps one display
# list: Ladybird's DisplayList is reference counted and the old one dies when the
# rendering thread takes the new one; here it is garbage once nothing refers to it, so
# after a collection the display lists' storage (the paint tag) is one list's, however
# many were recorded. The budgets of whole pages are tests/memory's.
#
# Copyright (c) 2026 the luce-browser authors.
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## The live blobs of the paint phase (display lists) after a collection.
func test_webview_paint_bytes() -> usize:
gc.heap_collect_garbage(webview_heap())
let census = webview_memory_census(webview_heap())
return census.blob_bytes_by_tag[(usize)web.MemoryTag.paint]
test "the census counts the page's phases, and repainting keeps one display list":
test_webview_platform()
let allocator: memory.Allocator = webview_heap()
with allocator:
let view = test_webview_open()
defer webview_destroy(view)
var log = TestWebViewLog()
webview_load(view, test_webview_file_url("plain.html"))
test_webview_wait_for_load(view, &log, "plain.html")
test_webview_sync_rendering(view, &log)
let census = webview_memory_census(webview_heap())
assert(census.cell_bytes_by_kind[(usize)WebViewMemoryCellKind.dom] > 0, "the census finds DOM nodes")
assert(census.blob_bytes_by_tag[(usize)web.MemoryTag.parse] > 0, "the parser's storage is tagged")
assert(census.blob_bytes_by_tag[(usize)web.MemoryTag.style] > 0, "style's storage is tagged")
assert(census.blob_bytes_by_tag[(usize)web.MemoryTag.layout] > 0, "layout's storage is tagged")
let one_list = test_webview_paint_bytes()
assert(one_list > 0, "the display list's storage is tagged")
# Each new viewport lays the page out again and records a new display list.
let serial = webview_frame_serial(view)
for round in 0..<(usize)12:
let width: i32 = 700 if round % 2 == 0 else 800
webview_set_viewport(view, gfx.IntSize(m_width = width, m_height = 600), 1.0)
test_webview_sync_rendering(view, &log)
assert(webview_frame_serial(view) >= serial + 12, "each viewport presented a frame")
assert(test_webview_paint_bytes() <= one_list * 2, "replaced display lists are collected")
test "the process's memory is measured on macOS and Linux":
let measured = webview_process_memory()
if os.macos or os.linux:
assert(measured.available and measured.resident > 0 and measured.peak_resident > 0)