-
Notifications
You must be signed in to change notification settings - Fork 44
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
Constant slices #584
Comments
(I should also note that this is orthogonal to / complementary to making byte-slicing itself reuse underlying data. I.e. taking a slice of a |
I've done a little more investigation into this and while I still think it will work, there are a couple more limitations that will restrict it:
So .. I still think this is basically ok and I'm going to try prototyping it anyways, but it might need to be a slightly-more-partial function, which fails with either We can also reduce the odds of the first issue causing a problem by reserving a few bits to identify the data segment, eg. support "up to 16" segments or something. That will probably handle all real-world cases. |
I've done a lot of experimenting with this and concluded it's not worthwhile. At least not unless we get feedback that it's really hurting us.
|
We should add a new variant of
RawVal
calledCSlice
that is a constant (and lazy) version ofBytes
, with the following structure in its 60 bits:[8 bits] -
Bytes
subtype (assuming we do Object subtypes. This limits subtypes to 256 possibilities, which is likely still far more than we'll ever need.[12 bits] - Numeric identifier for currently-running contract. This imposes a new (but I think fairly reasonable) limit of 4096 contracts loaded per Host.
[20 bits] - Offset in the constant data of the contract. This imposes a new (but I think fairly reasonable) size limit of 1MB on each contract.
[20 bits] - Length in the constant data of the contract. Same limit.
(Comments welcome below fiddling with these limits up and down -- I can imagine setting them differently, they just have to add up to 60 bits)
Numeric identifiers are assigned dynamically by the host as it loads contracts. Numeric identifier 0 is reserved to mean "the currently-running contract" and any time it's passed to a host function it's rewritten to use the actual assigned numeric identifier of that contract.
The point of
CSlice
is to occupy a space somewhere in-betweenObject(Bytes(...))
andSymbol
:Symbol
it can be calculated at compile time in the guest, embedded inconst
structures or emitted as a literal in the instruction stream.Symbol
it can be pushed very cheaply into the debug-event buffer on the host, and if it's never inspected further it does not cause any host-side allocations. The host does not need to worry about the memory it points to being short-lived in the guest, because the guest is promising that it is stored in the guest's constant-data section.Object(Bytes(...))
it can point to arbitrarily-long strings. When converted to an XDRSCVal
for returning from a contract or emitting into the event list, it's treated as though it wasObject(Bytes(...))
, just constructed on-demand.This might be hard to implement (or even impossible) depending on how easy or hard it is to correlate constant linear-memory addresses with offsets of the originating data, in the WASM data section. It might require an extra step of address-conversion when converting a "contract identity number 0" input-
CSlice
.We might also need to use a special host-side representation that's handles native-testing mode transparently (i.e. so that a
&'static str
or&'static [u8]
can be used throughEnvBase
).This, along with simply allowing
Bytes
arguments (orCSlice
s) in any host functions we currently restrict toSymbol
arguments, represents my best-guess about how to solve #463 . It's not perfect, sinceCSlice
is still Host-relative, whereasSymbol
is more universal, but since it's confined toRawVal
rather than bleeding into the XDR, I think it's probably something we can live with.The text was updated successfully, but these errors were encountered: