Skip to content

Refactor instance to avoid keeping a copy of Module#233

Closed
axic wants to merge 1 commit intomasterfrom
refactor-instance
Closed

Refactor instance to avoid keeping a copy of Module#233
axic wants to merge 1 commit intomasterfrom
refactor-instance

Conversation

@axic
Copy link
Member

@axic axic commented Mar 16, 2020

No description provided.

@axic
Copy link
Member Author

axic commented Apr 23, 2020

@gumb0 should I rebase this or drop it?

@gumb0
Copy link
Collaborator

gumb0 commented Apr 24, 2020

I think the only things we could discard in Module after instantiate are startfunc, elemsec, datasec and importsec (but not imported_* collections)

So maybe not worth it.

@axic
Copy link
Member Author

axic commented Apr 24, 2020

datasec could be rather big, many cases (precompiles) it is several hundred kilobytes.

@axic
Copy link
Member Author

axic commented May 8, 2020

This is made a bit more challenging with #281. Closing.

@axic axic closed this May 8, 2020
@axic axic deleted the refactor-instance branch May 8, 2020 16:56
@axic axic restored the refactor-instance branch October 6, 2020 15:50
@axic axic reopened this Oct 6, 2020
@axic axic added the refactoring Refactors a part of the codebase label Oct 9, 2020
@chfast
Copy link
Collaborator

chfast commented Oct 19, 2020

I was considering copying only required part of the module to the instance, but that would include all the code should be the biggest part of the module. Moreover, freeing the module is not beneficial short-term. Freeing actually cost you time.

Can we close this?

@axic
Copy link
Member Author

axic commented Oct 19, 2020

but that would include all the code should be the biggest part of the module

The code isn't the biggest, the data segment is the biggest, which is already copied.

@chfast
Copy link
Collaborator

chfast commented Oct 19, 2020

None of our benchmarks has bigger Data than Code.

wasm-objdump -h *.wasm

blake2b.wasm:   file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001a (size=0x00000010) count: 3
 Function start=0x0000001c end=0x00000021 (size=0x00000005) count: 4
    Table start=0x00000023 end=0x00000028 (size=0x00000005) count: 1
   Memory start=0x0000002a end=0x0000002d (size=0x00000003) count: 1
   Global start=0x0000002f end=0x00000044 (size=0x00000015) count: 3
   Export start=0x00000046 end=0x0000007b (size=0x00000035) count: 4
     Code start=0x0000007e end=0x00000aef (size=0x00000a71) count: 4
     Data start=0x00000af2 end=0x00000bfa (size=0x00000108) count: 1

ecpairing.wasm: file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x00000062 (size=0x00000058) count: 14
 Function start=0x00000064 end=0x0000009e (size=0x0000003a) count: 57
    Table start=0x000000a0 end=0x000000a5 (size=0x00000005) count: 1
   Memory start=0x000000a7 end=0x000000aa (size=0x00000003) count: 1
   Global start=0x000000ac end=0x000000c5 (size=0x00000019) count: 3
   Export start=0x000000c7 end=0x0000013f (size=0x00000078) count: 7
     Elem start=0x00000141 end=0x0000015c (size=0x0000001b) count: 1
     Code start=0x00000160 end=0x0003003c (size=0x0002fedc) count: 57
     Data start=0x0003003f end=0x000323d2 (size=0x00002393) count: 2
   Custom start=0x000323d5 end=0x00033030 (size=0x00000c5b) "name"

keccak256.wasm: file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001b (size=0x00000011) count: 3
 Function start=0x0000001d end=0x00000023 (size=0x00000006) count: 5
    Table start=0x00000025 end=0x0000002a (size=0x00000005) count: 1
   Memory start=0x0000002c end=0x0000002f (size=0x00000003) count: 1
   Global start=0x00000031 end=0x00000046 (size=0x00000015) count: 3
   Export start=0x00000048 end=0x0000007f (size=0x00000037) count: 4
     Code start=0x00000082 end=0x00001128 (size=0x000010a6) count: 5
     Data start=0x0000112b end=0x000011f3 (size=0x000000c8) count: 1

memset.wasm:    file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001b (size=0x00000011) count: 3
 Function start=0x0000001d end=0x00000021 (size=0x00000004) count: 3
    Table start=0x00000023 end=0x00000028 (size=0x00000005) count: 1
   Memory start=0x0000002a end=0x0000002d (size=0x00000003) count: 1
   Global start=0x0000002f end=0x00000044 (size=0x00000015) count: 3
   Export start=0x00000046 end=0x0000007a (size=0x00000034) count: 4
     Code start=0x0000007d end=0x00000251 (size=0x000001d4) count: 3

mul256_opt0.wasm:       file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x00000011 (size=0x00000007) count: 1
 Function start=0x00000013 end=0x00000015 (size=0x00000002) count: 1
    Table start=0x00000017 end=0x0000001c (size=0x00000005) count: 1
   Memory start=0x0000001e end=0x00000021 (size=0x00000003) count: 1
   Global start=0x00000023 end=0x0000002b (size=0x00000008) count: 1
   Export start=0x0000002d end=0x00000040 (size=0x00000013) count: 2
     Code start=0x00000043 end=0x00000346 (size=0x00000303) count: 1

ramanujan_pi.wasm:      file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001f (size=0x00000015) count: 4
 Function start=0x00000021 end=0x00000026 (size=0x00000005) count: 4
    Table start=0x00000028 end=0x0000002d (size=0x00000005) count: 1
   Memory start=0x0000002f end=0x00000032 (size=0x00000003) count: 1
   Global start=0x00000034 end=0x00000049 (size=0x00000015) count: 3
   Export start=0x0000004b end=0x0000007f (size=0x00000034) count: 4
     Code start=0x00000082 end=0x00000ac5 (size=0x00000a43) count: 4
     Data start=0x00000ac7 end=0x00000afe (size=0x00000037) count: 1

sha1.wasm:      file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001a (size=0x00000010) count: 3
 Function start=0x0000001c end=0x00000022 (size=0x00000006) count: 5
    Table start=0x00000024 end=0x00000029 (size=0x00000005) count: 1
   Memory start=0x0000002b end=0x0000002e (size=0x00000003) count: 1
   Global start=0x00000030 end=0x00000045 (size=0x00000015) count: 3
   Export start=0x00000047 end=0x00000079 (size=0x00000032) count: 4
     Code start=0x0000007c end=0x00001099 (size=0x0000101d) count: 5

sha256.wasm:    file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x0000001a (size=0x00000010) count: 3
 Function start=0x0000001c end=0x00000023 (size=0x00000007) count: 6
    Table start=0x00000025 end=0x0000002a (size=0x00000005) count: 1
   Memory start=0x0000002c end=0x0000002f (size=0x00000003) count: 1
   Global start=0x00000031 end=0x00000046 (size=0x00000015) count: 3
   Export start=0x00000048 end=0x0000007c (size=0x00000034) count: 4
     Code start=0x0000007f end=0x00001c9e (size=0x00001c1f) count: 6
     Data start=0x00001ca1 end=0x00001dc9 (size=0x00000128) count: 1

taylor_pi.wasm: file format wasm 0x1

Sections:

     Type start=0x0000000a end=0x00000013 (size=0x00000009) count: 2
 Function start=0x00000015 end=0x00000018 (size=0x00000003) count: 2
    Table start=0x0000001a end=0x0000001f (size=0x00000005) count: 1
   Memory start=0x00000021 end=0x00000024 (size=0x00000003) count: 1
   Global start=0x00000026 end=0x0000003b (size=0x00000015) count: 3
   Export start=0x0000003d end=0x0000006e (size=0x00000031) count: 4
     Code start=0x00000071 end=0x000000ff (size=0x0000008e) count: 2

@axic
Copy link
Member Author

axic commented Oct 19, 2020

The data section contains a sparse description of the memory. In many cases it is expanded to a larger output than the encoded version.

@axic
Copy link
Member Author

axic commented Apr 9, 2021

Rather outdated PR by now.

@axic axic closed this Apr 9, 2021
@axic axic deleted the refactor-instance branch April 9, 2021 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Refactors a part of the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants