Skip to content

[1.0 blocking] Implement Copy for JsValue (or alternative) #5371

@hansl

Description

@hansl

Currently, the only way to pass a JsValue to, say, two different APIs is to clone them. Clones are expensive with the current GC (as it requires a ref count inc/dec on clone/drop, and a mutex lock on drop).

This is blocking to 1.0 as it might require a public API breaking change.

This can also be fixed with the new GC. If it is, then this issue becomes a NOOP as JsValue itself would be Copy.

An alternative is to keep JsValue non-Copy, and implement a JsValueLite (those two things could be swapped to JsValueOwned and JsValue). The lite version of value would be akin to a weak ref to the value, and be copy-able but scoped to '_ (so you cannot hold a value of it internally without cloning). This would be safe as the GC never collects during API call stacks, only at the end. If a host/API wants to keep a value internally they would need to clone, getting the fully owned version of JsValue.

Since this might be useless work and be obsolete with the new GC, this was never implemented. But it should still gate the 1.0 release, in case the new GC cannot make JsValue copy.

Metadata

Metadata

Assignees

Labels

A-EnhancementNew feature or requestA-PerformancePerformance related changes and issuesC-GCIssue related to garbage collectionC-RuntimeIssues and PRs related to Boa's runtime features
No fields configured for Feature.

Projects

Status
To do

Relationships

None yet

Development

No branches or pull requests

Issue actions