rs-soroban-env icon indicating copy to clipboard operation
rs-soroban-env copied to clipboard

Cache contract id (and other frequent objects) in host

Open graydon opened this issue 2 years ago • 4 comments

We fetch contract IDs as hashes fairly often, which means we're either copying around 32-byte hashes in the host or converting them to 8-byte Objects that hold handles pointing to bytes in the host object array. That latter approach is ok as far as it goes, but we don't unique those bytes, and we do a fair number of conversions, so it's possible that we're winding up with quite a lot of copies of a given contract ID in the host object array.

We've talked about doing ubiquitous "interning" (forcing host objects to be unique when added to the table) and this is still a bit of a design decision to work through, but it should at least be possible to optionally ask for an object to be added uniquely, to cut down on cases like this.

graydon avatar Feb 09 '23 22:02 graydon

Decision: we're not going to do ubiquitous interning for now. It penalizes the common case (allocating actually-new objects) in favor of a rarer case (allocating duplicate objects). For objects we know we need to cache a widely-reused value of, we can cache that value.

graydon avatar Feb 16 '23 07:02 graydon

(we should still cache the contract ID, probably)

graydon avatar Feb 16 '23 07:02 graydon

Should probably also cache a variety of continuously-reused symbols and event-topic-vectors-containing-just-those-symbols.

graydon avatar Mar 09 '23 23:03 graydon

Discussed with @graydon and this can move to post V1 launch if we run out of time to get this done for v1.

anupsdf avatar Jun 22 '23 20:06 anupsdf