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

refactor: Allocate module dynamically #575

Merged
merged 2 commits into from
Oct 12, 2020
Merged

refactor: Allocate module dynamically #575

merged 2 commits into from
Oct 12, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Oct 5, 2020

This will simplify C API implementation part, allowing to handle modules and instances in the same manner.

@gumb0 gumb0 force-pushed the dynamic-module branch 2 times, most recently from 371941d to 0ccea9d Compare October 5, 2020 11:03
@codecov
Copy link

codecov bot commented Oct 5, 2020

Codecov Report

Merging #575 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #575      +/-   ##
==========================================
- Coverage   98.24%   98.23%   -0.01%     
==========================================
  Files          62       63       +1     
  Lines        9039     8995      -44     
==========================================
- Hits         8880     8836      -44     
  Misses        159      159              

@gumb0 gumb0 force-pushed the dynamic-module branch 2 times, most recently from fcee718 to af80e3e Compare October 5, 2020 13:55
@gumb0 gumb0 marked this pull request as ready for review October 6, 2020 10:31
@@ -87,13 +87,22 @@ struct Instance
};

// Instantiate a module.
std::unique_ptr<Instance> instantiate(Module module,
// Transfers ownership of passed module to instance.
std::unique_ptr<Instance> instantiate(std::unique_ptr<Module>&& module,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another possible option would be to have

  • for moving: std::unique_ptr<Instance> instantiate(std::unique_ptr<Module> module,
  • for copying: std::unique_ptr<Instance> instantiate(const Module& module,

but that would require even more changes to the tests to do either instantiate(std::move(module), ... or instantiate(*module, ...

I would better do it in a follower PR if it's a preferable variant.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the copy is to be made, better API is instantiate(Module module, ...)

test/utils/fizzy_engine.cpp Outdated Show resolved Hide resolved
@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 6, 2020

Clang 10 build with LTO, mostly no difference.

fizzy/parse/blake2b_mean                                           +0.0090         +0.0093            46            46            46            46
fizzy/instantiate/blake2b_mean                                     -0.0021         -0.0018            54            54            54            54
fizzy/execute/blake2b/512_bytes_rounds_1_mean                      +0.0046         +0.0048           217           218           217           218
fizzy/execute/blake2b/512_bytes_rounds_16_mean                     +0.0078         +0.0080          3279          3305          3279          3306
fizzy/parse/ecpairing_mean                                         -0.0025         -0.0019          2713          2707          2712          2707
fizzy/instantiate/ecpairing_mean                                   +0.0039         +0.0041          2838          2850          2839          2850
fizzy/execute/ecpairing/onepoint_mean                              +0.0114         +0.0117       1060043       1072120       1060062       1072416
fizzy/parse/keccak256_mean                                         +0.0048         +0.0043            84            85            84            85
fizzy/instantiate/keccak256_mean                                   -0.0045         -0.0046            94            94            94            94
fizzy/execute/keccak256/512_bytes_rounds_1_mean                    +0.0038         +0.0031           258           259           258           259
fizzy/execute/keccak256/512_bytes_rounds_16_mean                   +0.0035         +0.0029          3767          3780          3767          3778
fizzy/parse/memset_mean                                            +0.0002         -0.0003            11            11            11            11
fizzy/instantiate/memset_mean                                      -0.0127         -0.0132            18            18            18            18
fizzy/execute/memset/256_bytes_mean                                +0.0265         +0.0260            17            17            17            17
fizzy/execute/memset/60000_bytes_mean                              +0.0210         +0.0206          3731          3809          3731          3808
fizzy/parse/mul256_opt0_mean                                       -0.0195         -0.0198            15            15            15            15
fizzy/instantiate/mul256_opt0_mean                                 -0.0170         -0.0152            22            21            22            21
fizzy/execute/mul256_opt0/input1_mean                              +0.0147         +0.0180            71            72            71            72
fizzy/parse/ramanujan_pi_mean                                      -0.0028         -0.0007            49            48            48            48
fizzy/instantiate/ramanujan_pi_mean                                -0.0105         -0.0090            57            56            57            56
fizzy/execute/ramanujan_pi/33_runs_mean                            -0.0202         -0.0191           292           286           292           286
fizzy/parse/sha1_mean                                              +0.0015         +0.0023            76            76            76            76
fizzy/instantiate/sha1_mean                                        +0.0013         +0.0020            84            84            84            84
fizzy/execute/sha1/512_bytes_rounds_1_mean                         +0.0271         +0.0277           225           231           224           231
fizzy/execute/sha1/512_bytes_rounds_16_mean                        +0.0246         +0.0252          3131          3208          3129          3208
fizzy/parse/sha256_mean                                            +0.0083         +0.0089           128           129           128           129
fizzy/instantiate/sha256_mean                                      +0.0087         +0.0092           137           138           137           138
fizzy/execute/sha256/512_bytes_rounds_1_mean                       -0.0358         -0.0353           216           208           216           208
fizzy/execute/sha256/512_bytes_rounds_16_mean                      -0.0425         -0.0420          2973          2847          2972          2847
fizzy/parse/taylor_pi_mean                                         -0.0072         -0.0067             5             5             5             5
fizzy/instantiate/taylor_pi_mean                                   -0.0228         -0.0223            12            12            12            12
fizzy/execute/taylor_pi/pi_1000000_runs_mean                       -0.0209         -0.0204         97119         95091         97070         95093
fizzy/parse/micro/eli_interpreter_mean                             +0.0067         +0.0073             8             8             8             8
fizzy/instantiate/micro/eli_interpreter_mean                       -0.0033         -0.0028            15            15            15            15
fizzy/execute/micro/eli_interpreter/exec105_mean                   +0.1369         +0.1375            12            13            12            13
fizzy/parse/micro/factorial_mean                                   +0.0175         +0.0181             2             2             2             2
fizzy/instantiate/micro/factorial_mean                             -0.0151         -0.0145             3             3             3             3
fizzy/execute/micro/factorial/20_mean                              -0.0339         -0.0327             1             1             1             1
fizzy/parse/micro/fibonacci_mean                                   +0.0112         +0.0118             2             2             2             2
fizzy/instantiate/micro/fibonacci_mean                             -0.0125         -0.0128             3             3             3             3
fizzy/execute/micro/fibonacci/24_mean                              -0.0179         -0.0173         12665         12438         12656         12437
fizzy/parse/micro/host_adler32_mean                                +0.0023         +0.0030             3             3             3             3
fizzy/instantiate/micro/host_adler32_mean                          -0.0448         -0.0442             8             8             8             8
fizzy/execute/micro/host_adler32/1_mean                            +0.0022         +0.0028             0             0             0             0
fizzy/execute/micro/host_adler32/1000_mean                         -0.0141         -0.0140            76            75            76            75
fizzy/parse/micro/spinner_mean                                     +0.0132         +0.0130             2             2             2             2
fizzy/instantiate/micro/spinner_mean                               -0.0159         -0.0160             3             3             3             3
fizzy/execute/micro/spinner/1_mean                                 -0.0029         -0.0034             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                              -0.0254         -0.0255            22            22            22            22
fizzy/parse/stress/guido-fuzzer-find-1_mean                        +0.0011         +0.0003           278           278           278           278
fizzy/instantiate/stress/guido-fuzzer-find-1_mean                  -0.0016         -0.0015           327           327           327           327

@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 6, 2020

Now after rebase I'm getting significant slowdown.

@chfast Could you try benchmarking this?

@chfast
Copy link
Collaborator

chfast commented Oct 7, 2020

fizzy/parse/blake2b_mean                                           +0.0364         +0.0364            23            23            23            23
fizzy/instantiate/blake2b_mean                                     +0.0263         +0.0263            26            27            26            27
fizzy/execute/blake2b/512_bytes_rounds_1_mean                      +0.0843         +0.0843            77            83            77            83
fizzy/execute/blake2b/512_bytes_rounds_16_mean                     +0.0869         +0.0869          1158          1259          1158          1259
fizzy/parse/ecpairing_mean                                         +0.0218         +0.0218          1362          1392          1362          1392
fizzy/instantiate/ecpairing_mean                                   +0.0417         +0.0417          1389          1447          1389          1447
fizzy/execute/ecpairing/onepoint_mean                              +0.0529         +0.0529        377317        397270        377321        397274
fizzy/parse/keccak256_mean                                         +0.0213         +0.0213            42            43            42            43
fizzy/instantiate/keccak256_mean                                   +0.0150         +0.0150            46            47            46            47
fizzy/execute/keccak256/512_bytes_rounds_1_mean                    +0.0414         +0.0414            94            98            94            98
fizzy/execute/keccak256/512_bytes_rounds_16_mean                   +0.0468         +0.0468          1372          1436          1372          1436
fizzy/parse/memset_mean                                            +0.0374         +0.0374             6             6             6             6
fizzy/instantiate/memset_mean                                      +0.0098         +0.0098             9             9             9             9
fizzy/execute/memset/256_bytes_mean                                +0.0695         +0.0695             6             7             6             7
fizzy/execute/memset/60000_bytes_mean                              +0.0728         +0.0728          1426          1530          1426          1530
fizzy/parse/mul256_opt0_mean                                       +0.0102         +0.0102             8             8             8             8
fizzy/instantiate/mul256_opt0_mean                                 -0.0041         -0.0041            11            11            11            11
fizzy/execute/mul256_opt0/input1_mean                              +0.0285         +0.0285            25            26            25            26
fizzy/parse/ramanujan_pi_mean                                      +0.0245         +0.0245            23            24            23            24
fizzy/instantiate/ramanujan_pi_mean                                +0.0188         +0.0188            27            27            27            27
fizzy/execute/ramanujan_pi/33_runs_mean                            -0.2506         -0.2506           165           124           165           124
fizzy/parse/sha1_mean                                              +0.0290         +0.0290            37            38            37            38
fizzy/instantiate/sha1_mean                                        +0.0231         +0.0231            41            42            41            42
fizzy/execute/sha1/512_bytes_rounds_1_mean                         +0.0824         +0.0824            84            91            84            91
fizzy/execute/sha1/512_bytes_rounds_16_mean                        +0.0853         +0.0853          1166          1265          1166          1265
fizzy/parse/sha256_mean                                            +0.0320         +0.0320            62            64            62            64
fizzy/instantiate/sha256_mean                                      +0.0523         +0.0523            66            70            66            70
fizzy/execute/sha256/512_bytes_rounds_1_mean                       +0.0378         +0.0378            87            90            87            90
fizzy/execute/sha256/512_bytes_rounds_16_mean                      +0.0394         +0.0394          1195          1242          1195          1242
fizzy/parse/taylor_pi_mean                                         +0.0369         +0.0369             2             3             2             3
fizzy/instantiate/taylor_pi_mean                                   +0.0081         +0.0081             6             6             6             6
fizzy/execute/taylor_pi/pi_1000000_runs_mean                       +0.0027         +0.0027         40057         40167         40057         40167
fizzy/parse/micro/eli_interpreter_mean                             +0.0252         +0.0252             4             4             4             4
fizzy/instantiate/micro/eli_interpreter_mean                       +0.0013         +0.0013             8             8             8             8
fizzy/execute/micro/eli_interpreter/exec105_mean                   +0.1229         +0.1229             4             5             4             5
fizzy/parse/micro/factorial_mean                                   +0.0132         +0.0132             1             1             1             1
fizzy/instantiate/micro/factorial_mean                             -0.0417         -0.0417             1             1             1             1
fizzy/execute/micro/factorial/20_mean                              +0.0973         +0.0973             1             1             1             1
fizzy/parse/micro/fibonacci_mean                                   +0.0493         +0.0493             1             1             1             1
fizzy/instantiate/micro/fibonacci_mean                             -0.0113         -0.0113             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                              +0.0699         +0.0699          4874          5215          4874          5215
fizzy/parse/micro/host_adler32_mean                                +0.0253         +0.0253             2             2             2             2
fizzy/instantiate/micro/host_adler32_mean                          -0.0262         -0.0262             4             4             4             4
fizzy/execute/micro/host_adler32/1_mean                            +0.0987         +0.0987             0             0             0             0
fizzy/execute/micro/host_adler32/1000_mean                         +0.0976         +0.0976            30            33            30            33
fizzy/parse/micro/spinner_mean                                     +0.0428         +0.0428             1             1             1             1
fizzy/instantiate/micro/spinner_mean                               -0.0380         -0.0380             1             1             1             1
fizzy/execute/micro/spinner/1_mean                                 +0.0005         +0.0005             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                              +0.1761         +0.1761             9            10             9            10
fizzy/parse/stress/guido-fuzzer-find-1_mean                        +0.0799         +0.0799           116           126           116           126
fizzy/instantiate/stress/guido-fuzzer-find-1_mean                  +0.1039         +0.1039           146           161           146           161

Might be related to similar issue in #577 and other optimization PRs.

@chfast chfast removed their assignment Oct 7, 2020
@@ -373,6 +373,16 @@ std::unique_ptr<Instance> instantiate(Module module,
return instance;
}

std::unique_ptr<Instance> instantiate(const std::unique_ptr<Module>& module,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not good idea, because it is too easy to copy Module unintentionally (as we have right now). If this is for avoid unittest modifications, move it test/.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is mostly for tests, but without this overload here it would be not clear why the only instantiate has unique_ptr<Module>&& parameter and not unique_ptr<Module> (the reason is rvalue-reference allows the call with lvalue module variable to be unambiguous)

Ok let me try the change suggested in #575 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

A comment explaining this would be enough to me. Later unit tests can be updated, when API is stable and we are happy with it.

Copy link
Collaborator Author

@gumb0 gumb0 Oct 8, 2020

Choose a reason for hiding this comment

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

I moved second instantiate to test/instantiate_helpers.hpp and changed the main one to take unique_ptr by value, PTAL.

@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 8, 2020

Benchmarked again after rebase.

Clang with LTO

fizzy/parse/blake2b_mean                                           +0.0431         +0.0432            46            48            46            48
fizzy/instantiate/blake2b_mean                                     -0.0082         -0.0081            52            52            52            52
fizzy/execute/blake2b/512_bytes_rounds_1_mean                      -0.0196         -0.0187           209           205           209           205
fizzy/execute/blake2b/512_bytes_rounds_16_mean                     -0.0169         -0.0167          3129          3076          3128          3076
fizzy/parse/ecpairing_mean                                         -0.0275         -0.0275          2685          2611          2685          2611
fizzy/instantiate/ecpairing_mean                                   -0.0176         -0.0176          2766          2717          2765          2717
fizzy/execute/ecpairing/onepoint_mean                              -0.0076         -0.0075       1011395       1003738       1011332       1003701
fizzy/parse/keccak256_mean                                         +0.0167         +0.0167            83            85            83            85
fizzy/instantiate/keccak256_mean                                   +0.0018         +0.0018            91            91            91            91
fizzy/execute/keccak256/512_bytes_rounds_1_mean                    +0.0325         +0.0324           252           260           252           260
fizzy/execute/keccak256/512_bytes_rounds_16_mean                   +0.0263         +0.0263          3734          3832          3734          3832
fizzy/parse/memset_mean                                            -0.0295         -0.0294            11            11            11            11
fizzy/instantiate/memset_mean                                      -0.0399         -0.0399            18            17            18            17
fizzy/execute/memset/256_bytes_mean                                -0.0016         -0.0015            17            17            17            17
fizzy/execute/memset/60000_bytes_mean                              -0.0067         -0.0067          3693          3668          3692          3668
fizzy/parse/mul256_opt0_mean                                       -0.0264         -0.0263            14            14            14            14
fizzy/instantiate/mul256_opt0_mean                                 -0.0361         -0.0360            21            20            21            20
fizzy/execute/mul256_opt0/input1_mean                              -0.0223         -0.0222            67            66            67            66
fizzy/parse/ramanujan_pi_mean                                      +0.0273         +0.0274            48            49            48            49
fizzy/instantiate/ramanujan_pi_mean                                +0.0082         +0.0084            55            56            55            56
fizzy/execute/ramanujan_pi/33_runs_mean                            -0.0001         -0.0000           275           275           275           275
fizzy/parse/sha1_mean                                              +0.0081         +0.0082            75            75            75            75
fizzy/instantiate/sha1_mean                                        -0.0054         -0.0052            83            82            83            82
fizzy/execute/sha1/512_bytes_rounds_1_mean                         -0.0457         -0.0456           224           214           224           214
fizzy/execute/sha1/512_bytes_rounds_16_mean                        -0.0476         -0.0476          3125          2976          3125          2976
fizzy/parse/sha256_mean                                            +0.0123         +0.0124           126           128           126           128
fizzy/instantiate/sha256_mean                                      -0.0050         -0.0050           135           134           135           134
fizzy/execute/sha256/512_bytes_rounds_1_mean                       -0.0218         -0.0218           207           202           207           202
fizzy/execute/sha256/512_bytes_rounds_16_mean                      -0.0162         -0.0162          2809          2763          2809          2763
fizzy/parse/taylor_pi_mean                                         -0.0056         -0.0055             5             5             5             5
fizzy/instantiate/taylor_pi_mean                                   -0.0391         -0.0390            12            11            12            11
fizzy/execute/taylor_pi/pi_1000000_runs_mean                       -0.0079         -0.0078         93212         92478         93202         92475
fizzy/parse/micro/eli_interpreter_mean                             -0.0091         -0.0090             8             8             8             8
fizzy/instantiate/micro/eli_interpreter_mean                       -0.0254         -0.0254            14            14            14            14
fizzy/execute/micro/eli_interpreter/exec105_mean                   -0.0252         -0.0252            12            11            12            11
fizzy/parse/micro/factorial_mean                                   -0.0098         -0.0098             2             2             2             2
fizzy/instantiate/micro/factorial_mean                             -0.0757         -0.0756             2             2             2             2
fizzy/execute/micro/factorial/20_mean                              -0.0329         -0.0328             1             1             1             1
fizzy/parse/micro/fibonacci_mean                                   -0.0046         -0.0046             2             2             2             2
fizzy/instantiate/micro/fibonacci_mean                             -0.0650         -0.0649             3             3             3             3
fizzy/execute/micro/fibonacci/24_mean                              -0.0006         -0.0006         12088         12080         12087         12080
fizzy/parse/micro/host_adler32_mean                                +0.0183         +0.0182             3             3             3             3
fizzy/instantiate/micro/host_adler32_mean                          -0.0303         -0.0302             7             7             7             7
fizzy/execute/micro/host_adler32/1_mean                            -0.0255         -0.0254             0             0             0             0
fizzy/execute/micro/host_adler32/1000_mean                         -0.0976         -0.0975            79            72            79            72
fizzy/parse/micro/spinner_mean                                     -0.0003         -0.0003             2             2             2             2
fizzy/instantiate/micro/spinner_mean                               -0.0853         -0.0852             2             2             2             2
fizzy/execute/micro/spinner/1_mean                                 -0.0026         -0.0025             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                              -0.0227         -0.0226            21            21            21            21
fizzy/parse/stress/guido-fuzzer-find-1_mean                        -0.0300         -0.0299           276           268           276           268
fizzy/instantiate/stress/guido-fuzzer-find-1_mean                  -0.0218         -0.0216           324           317           324           317

GCC with LTO

fizzy/parse/blake2b_mean                                           +0.0264         +0.0264            49            51            49            51
fizzy/instantiate/blake2b_mean                                     +0.0145         +0.0145            57            57            57            57
fizzy/execute/blake2b/512_bytes_rounds_1_mean                      -0.0613         -0.0613           206           193           206           193
fizzy/execute/blake2b/512_bytes_rounds_16_mean                     -0.0538         -0.0538          3074          2909          3074          2908
fizzy/parse/ecpairing_mean                                         +0.0368         +0.0368          2925          3033          2925          3032
fizzy/instantiate/ecpairing_mean                                   +0.0294         +0.0295          3029          3118          3028          3118
fizzy/execute/ecpairing/onepoint_mean                              -0.0275         -0.0275       1003712        976139       1003649        976000
fizzy/parse/keccak256_mean                                         +0.0203         +0.0204            92            94            92            94
fizzy/instantiate/keccak256_mean                                   +0.0128         +0.0128            99           101            99           101
fizzy/execute/keccak256/512_bytes_rounds_1_mean                    -0.1476         -0.1477           269           230           269           230
fizzy/execute/keccak256/512_bytes_rounds_16_mean                   -0.1366         -0.1366          3939          3401          3939          3401
fizzy/parse/memset_mean                                            +0.0201         +0.0201            12            13            12            13
fizzy/instantiate/memset_mean                                      -0.0133         -0.0133            19            19            19            19
fizzy/execute/memset/256_bytes_mean                                -0.0881         -0.0880            17            15            17            15
fizzy/execute/memset/60000_bytes_mean                              -0.0817         -0.0817          3625          3329          3624          3328
fizzy/parse/mul256_opt0_mean                                       +0.0061         +0.0062            17            17            17            17
fizzy/instantiate/mul256_opt0_mean                                 -0.0094         -0.0094            23            23            23            23
fizzy/execute/mul256_opt0/input1_mean                              -0.0705         -0.0705            69            64            69            64
fizzy/parse/ramanujan_pi_mean                                      +0.0102         +0.0103            50            51            50            51
fizzy/instantiate/ramanujan_pi_mean                                -0.0044         -0.0044            58            57            58            57
fizzy/execute/ramanujan_pi/33_runs_mean                            -0.0986         -0.0986           305           275           305           275
fizzy/parse/sha1_mean                                              +0.0278         +0.0279            82            84            82            84
fizzy/instantiate/sha1_mean                                        +0.0182         +0.0183            90            91            90            91
fizzy/execute/sha1/512_bytes_rounds_1_mean                         +0.0244         +0.0246           222           227           222           227
fizzy/execute/sha1/512_bytes_rounds_16_mean                        +0.0290         +0.0290          3078          3168          3078          3168
fizzy/parse/sha256_mean                                            +0.0285         +0.0285           138           142           138           142
fizzy/instantiate/sha256_mean                                      +0.0208         +0.0208           146           149           146           149
fizzy/execute/sha256/512_bytes_rounds_1_mean                       +0.0017         +0.0017           226           226           226           226
fizzy/execute/sha256/512_bytes_rounds_16_mean                      -0.0008         +0.0003          3103          3100          3100          3100
fizzy/parse/taylor_pi_mean                                         +0.0323         +0.0323             5             5             5             5
fizzy/instantiate/taylor_pi_mean                                   -0.0183         -0.0183            12            12            12            12
fizzy/execute/taylor_pi/pi_1000000_runs_mean                       -0.0782         -0.0782         94403         87019         94401         87016
fizzy/parse/micro/eli_interpreter_mean                             +0.0048         +0.0051             8             8             8             8
fizzy/instantiate/micro/eli_interpreter_mean                       -0.0288         -0.0286            15            15            15            15
fizzy/execute/micro/eli_interpreter/exec105_mean                   -0.0646         -0.0641            11            10            11            10
fizzy/parse/micro/factorial_mean                                   +0.0364         +0.0364             2             2             2             2
fizzy/instantiate/micro/factorial_mean                             -0.0402         -0.0401             3             2             3             2
fizzy/execute/micro/factorial/20_mean                              -0.0241         -0.0240             1             1             1             1
fizzy/parse/micro/fibonacci_mean                                   +0.0359         +0.0360             3             3             3             3
fizzy/instantiate/micro/fibonacci_mean                             -0.0225         -0.0220             3             3             3             3
fizzy/execute/micro/fibonacci/24_mean                              +0.0054         +0.0055         11603         11666         11601         11665
fizzy/parse/micro/host_adler32_mean                                +0.0455         +0.0456             4             4             4             4
fizzy/instantiate/micro/host_adler32_mean                          -0.0460         -0.0459             8             7             8             7
fizzy/execute/micro/host_adler32/1_mean                            -0.0357         -0.0356             0             0             0             0
fizzy/execute/micro/host_adler32/1000_mean                         -0.0487         -0.0487            74            70            74            70
fizzy/parse/micro/spinner_mean                                     +0.0369         +0.0369             2             2             2             2
fizzy/instantiate/micro/spinner_mean                               -0.0340         -0.0339             2             2             2             2
fizzy/execute/micro/spinner/1_mean                                 -0.0465         -0.0465             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                              -0.1197         -0.1197            23            20            23            20
fizzy/parse/stress/guido-fuzzer-find-1_mean                        +0.0183         +0.0183           271           276           271           276
fizzy/instantiate/stress/guido-fuzzer-find-1_mean                  +0.0114         +0.0114           321           325           321           325

@gumb0 gumb0 requested review from chfast and axic October 8, 2020 10:19
lib/fizzy/instantiate.hpp Outdated Show resolved Hide resolved
@@ -171,7 +171,7 @@ TEST(execute_call, call_indirect_imported_table)
"0061736d01000000010a026000017f60017f017f020a01016d01740170010514030201010a0901070020001100"
"000b");

const Module module = parse(bin);
const auto module = parse(bin);
Copy link
Member

Choose a reason for hiding this comment

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

Can these thing be really const when it is a unique_ptr?

Copy link
Collaborator

@chfast chfast Oct 8, 2020

Choose a reason for hiding this comment

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

It can be, but you will not be able to move it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, const unique_ptr means you can't change the wrapped pointer.

@@ -31,7 +32,7 @@ TEST(end_to_end, milestone1)
const auto wasm = from_hex(
"0061736d0100000001070160027f7f017f030201000a13011101017f200020016a20026a220220006a0b");
const auto module = parse(wasm);
auto instance = instantiate(module);
auto instance = instantiate(*module);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the better change is to "inline" the module variable (CLion has a refactoring for that).

Suggested change
auto instance = instantiate(*module);
auto instance = instantiate(parse(bin));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed it everywhere, where possible, I think (i.e. where module variable is used only once in test)

@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 8, 2020

Squashed.

@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 9, 2020

Changed to parse returning unique_ptr<const Module>. That required const_casting in a couple of tests that modify code after parse.

Also note that const Module might not live well with refactoring like #233. But I think for now it's better.


return module;
return std::unique_ptr<const Module>(module.release());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know, it was not there first, but then some warning/sanitizers comlained.

Specifically, one warning claimed that returning different, but compatible type may lead to additional copying on some older compilers, and std::move(module) was adviced to force the move.

And then another one warned against return with std::move :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please disable -Wreturn-std-move-in-c++11 in Clang.

module.codesec.emplace_back(Code{1, 0, {Instr::local_get, instr, Instr::end}, {0, 0, 0, 0}});
module->typesec.emplace_back(FuncType{{ValType::i32}, {ValType::i32}});
module->funcsec.emplace_back(TypeIdx{0});
module->codesec.emplace_back(Code{1, 0, {Instr::local_get, instr, Instr::end}, {0, 0, 0, 0}});

return execute(module, 0, {arg});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe don't use test helpers here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

@@ -62,6 +62,7 @@ if(WEVERYTHING)
-Wno-double-promotion
-Wno-float-equal
-Wno-padded
-Wno-return-std-move-in-c++11
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@chfast is this ok or should I disable it only for clang somehow?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You disabled it only for -Weverything. If that's intentional, then we are fine as -Weverything only make sense for Clang. I'm assuming -Wreturn-std-move-in-c++11 is not enabled in default build.

@@ -62,6 +62,7 @@ if(WEVERYTHING)
-Wno-double-promotion
-Wno-float-equal
-Wno-padded
-Wno-return-std-move-in-c++11
Copy link
Collaborator

Choose a reason for hiding this comment

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

You disabled it only for -Weverything. If that's intentional, then we are fine as -Weverything only make sense for Clang. I'm assuming -Wreturn-std-move-in-c++11 is not enabled in default build.

@gumb0
Copy link
Collaborator Author

gumb0 commented Oct 12, 2020

You disabled it only for -Weverything. If that's intentional, then we are fine as -Weverything only make sense for Clang. I'm assuming -Wreturn-std-move-in-c++11 is not enabled in default build.

Yes, it's fine in default build.

@gumb0 gumb0 merged commit c00d177 into master Oct 12, 2020
@gumb0 gumb0 deleted the dynamic-module branch October 12, 2020 12:52
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.

3 participants