Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: partial workaround for high address support #62

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

chrisdickinson
Copy link
Contributor

@chrisdickinson chrisdickinson commented Apr 5, 2024

Some SDKs, like the js-sdk, store block index information in the top 16 bits of the 64-bit memory address. This is incompatible with the JS-PDK at present, since we truncate addresses to 32 bits. In advance of BigInt support in Javy/quickjs-wasm-sys, expose memory offset and lengths as JS Float values. This leans on the JS convention of storing (up to 53 bits of) integer data losslessly in an f64.

This gives us 5 bits of block index for the JS-SDK, enough room for slaps roof of memory allocator 32 allocations in this bad boy (before requiring an extism memory reset.)

QuickJS itself supports bigint, so it's a matter of looping that functionality out through quickjs-sys. (I haven't been able to find a technical reason this wasn't done initially, though that doesn't mean there aren't reasons!)

Some SDKs, like the js-sdk, store block index information in the top 16 bits of
the 64-bit memory address. This is incompatible with the JS-PDK at present,
since we truncate addresses to 32 bits. In advance of BigInt support in
Javy/quickjs-wasm-sys, expose memory offset and lengths as JS Float values.
This leans on the JS convention of storing (up to 53 bits of) integer data
losslessly in an f64.

This gives us 5 bits of block index for the JS-SDK, enough room for *slaps roof
of memory allocator* 31 allocations in this bad boy (before requiring an extism
memory reset.)

QuickJS itself supports bigint, so it's a matter of looping that functionality
out through quickjs-sys. (I haven't been able to find a technical reason this wasn't
done initially, though that doesn't mean there aren't reasons!)
@chrisdickinson chrisdickinson requested review from bhelx and zshipko April 5, 2024 18:30
@nilslice
Copy link
Member

nilslice commented Apr 5, 2024

slaps roof of memory allocator

🤣

@@ -442,47 +442,63 @@ fn build_memory(context: &JSContextRef) -> anyhow::Result<JSValueRef> {
let data = data.as_bytes()?;
let m = extism_pdk::Memory::from_bytes(data)?;
let mut mem = HashMap::new();
let offset = JSValue::Int(m.offset() as i32);
let len = JSValue::Int(m.len() as i32);
let offset = JSValue::Float(m.offset() as f64);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and makes sense to me, but only really in the context of this PR. I think a single comment here about why we're packing the offset into a float may be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point – added a note!

@chrisdickinson chrisdickinson force-pushed the chris/20240405-workaround-for-high-bytes branch from 6497fc3 to 03fb8cd Compare April 8, 2024 16:21
Copy link
Contributor

@zshipko zshipko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@chrisdickinson
Copy link
Contributor Author

Thanks for the reviews, all!

@chrisdickinson chrisdickinson merged commit f66d576 into main Apr 8, 2024
4 checks passed
@chrisdickinson chrisdickinson deleted the chris/20240405-workaround-for-high-bytes branch April 8, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants