mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-30 08:24:51 -04:00
Rather than having everything tied to the page's memory (arena, factory), most things are now tied to an IDBTransaction and its arena. The IDBTransaction is reference counted and finalized with v8. The lifecycle is relatively complicated compared to anything else we have, which is a concern, but using the page arena seems like a dealbreaker to me. Any "child" created for the transaction (e.g. IDBRequest) has its v8 acquireRef and releaseRef forwarded to the Transaction. This should make v8's usage safe. However, in addition to this, Zig itself must take a RC whenever a drain is scheduled AND whenever the transaction is parked in the engine. And these things, especially on cleanup, can be a little messy. The _awful_ cursor allocations have been improved by a local re-used ArrayLists for the key/primary key/value. So rather than accumulating _every_ allocation we now only capture the peak. One final memory-related area this commit addresses is the lifetime difference between Transactions (Page) and Engine (Session). This is problematic because the Engine can reference the Transaction. On js.Context deinit, the engine is notified and all related Transactions are canceled/removed. This is...unusual in our design. We have other similar cases that use a list on the frame/GWS to track resources to cleanup. But, the Engine already _has_ to have this list so rather than book-keeping in Engine AND Frame AND WGS, only Engine has a list at the cost of js.Context having to notify it on teardown.