Skip to content

Commit

Permalink
Optimize derived class construction (#753)
Browse files Browse the repository at this point in the history
We were emitting gobs of inefficient bytecode that created an arguments
array on the stack, then applied it to the parent constructor.

Add a new opcode for initializing a derived class. Speeds up construction
by 500%, although sadly that is not visible in the web-tooling-benchmark,
only in micro-benchmarks.

Fixes: #752
  • Loading branch information
bnoordhuis authored Jan 5, 2025
1 parent 6e43400 commit 5b609f1
Show file tree
Hide file tree
Showing 8 changed files with 1,687 additions and 1,698 deletions.
32 changes: 16 additions & 16 deletions gen/function_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ const uint8_t qjsc_function_source[314] = {
0x10, 0x00, 0x01, 0x00, 0xe4, 0x01, 0x00, 0x01,
0x00, 0xc6, 0x03, 0x00, 0x0d, 0xc4, 0x03, 0x01,
0x01, 0x0c, 0x43, 0xfa, 0x01, 0xc4, 0x03, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbc,
0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbd,
0x2a, 0x28, 0xc0, 0x03, 0x03, 0x01, 0x00, 0x1a,
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32,
0x20, 0x7d, 0x0c, 0x03, 0xc2, 0x04, 0x08, 0xcc,
0x08, 0xea, 0x05, 0xbf, 0x00, 0xe2, 0x29, 0x04,
0xe4, 0x00, 0x00, 0x00, 0xe1, 0x61, 0x00, 0x00,
0xde, 0x42, 0x38, 0x00, 0x00, 0x00, 0x24, 0x00,
0x00, 0xc9, 0x62, 0x00, 0x00, 0x65, 0x00, 0x00,
0xaf, 0xea, 0x0b, 0x38, 0x95, 0x00, 0x00, 0x00,
0x62, 0x00, 0x00, 0xef, 0x2f, 0x61, 0x02, 0x00,
0x61, 0x01, 0x00, 0x38, 0x3b, 0x00, 0x00, 0x00,
0x65, 0x00, 0x00, 0x04, 0xe2, 0x00, 0x00, 0x00,
0x9d, 0x31, 0x01, 0x00, 0x03, 0x00, 0xca, 0x62,
0x01, 0x00, 0x42, 0x38, 0x00, 0x00, 0x00, 0x24,
0x00, 0x00, 0xcb, 0x62, 0x02, 0x00, 0x65, 0x00,
0x00, 0xaf, 0xea, 0x0b, 0x38, 0x95, 0x00, 0x00,
0x00, 0x62, 0x02, 0x00, 0xef, 0x2f, 0x68, 0x02,
0x00, 0x68, 0x01, 0x00, 0x06, 0x2e, 0xc0, 0x03,
0x20, 0x7d, 0x0c, 0x03, 0xc3, 0x04, 0x08, 0xcd,
0x08, 0xeb, 0x05, 0xc0, 0x00, 0xe3, 0x29, 0x04,
0xe4, 0x00, 0x00, 0x00, 0xe2, 0x62, 0x00, 0x00,
0xdf, 0x43, 0x38, 0x00, 0x00, 0x00, 0x24, 0x00,
0x00, 0xca, 0x63, 0x00, 0x00, 0x66, 0x00, 0x00,
0xb0, 0xeb, 0x0b, 0x39, 0x95, 0x00, 0x00, 0x00,
0x63, 0x00, 0x00, 0xf0, 0x30, 0x62, 0x02, 0x00,
0x62, 0x01, 0x00, 0x39, 0x3b, 0x00, 0x00, 0x00,
0x66, 0x00, 0x00, 0x04, 0xe2, 0x00, 0x00, 0x00,
0x9e, 0x32, 0x01, 0x00, 0x03, 0x00, 0xcb, 0x63,
0x01, 0x00, 0x43, 0x38, 0x00, 0x00, 0x00, 0x24,
0x00, 0x00, 0xcc, 0x63, 0x02, 0x00, 0x66, 0x00,
0x00, 0xb0, 0xeb, 0x0b, 0x39, 0x95, 0x00, 0x00,
0x00, 0x63, 0x02, 0x00, 0xf0, 0x30, 0x69, 0x02,
0x00, 0x69, 0x01, 0x00, 0x06, 0x2f, 0xc0, 0x03,
0x01, 0x01, 0x0e, 0x00, 0x1c, 0x0a, 0x2a, 0x5d,
0x18, 0x00, 0x10, 0x08, 0x25, 0x76, 0x0e, 0x5d,
0x18, 0x00,
Expand Down
6 changes: 3 additions & 3 deletions gen/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const uint8_t qjsc_hello[103] = {
0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64,
0x0d, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x20, 0xfa, 0x01, 0xa2, 0x01, 0x00, 0x00,
0x00, 0x03, 0x00, 0x00, 0x19, 0x00, 0x08, 0xea,
0x02, 0x29, 0x38, 0xe1, 0x00, 0x00, 0x00, 0x42,
0x00, 0x03, 0x00, 0x00, 0x19, 0x00, 0x08, 0xeb,
0x02, 0x29, 0x39, 0xe1, 0x00, 0x00, 0x00, 0x43,
0xe2, 0x00, 0x00, 0x00, 0x04, 0xe3, 0x00, 0x00,
0x00, 0x24, 0x01, 0x00, 0x0e, 0x06, 0x2e, 0xc0,
0x00, 0x24, 0x01, 0x00, 0x0e, 0x06, 0x2f, 0xc0,
0x03, 0x01, 0x01, 0x02, 0x48, 0x0e, 0x00,
};

Expand Down
26 changes: 13 additions & 13 deletions gen/hello_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const uint8_t qjsc_fib_module[282] = {
0x01, 0x01, 0x09, 0x00, 0xc2, 0x03, 0x00, 0x01,
0x0c, 0x43, 0xfa, 0x01, 0xc2, 0x03, 0x01, 0x00,
0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xc4, 0x03,
0x00, 0x01, 0x00, 0xc2, 0x03, 0x00, 0x00, 0xd1,
0xb4, 0xa7, 0xea, 0x03, 0xb4, 0x28, 0xd1, 0xb5,
0xac, 0xea, 0x03, 0xb5, 0x28, 0xdd, 0xd1, 0xb5,
0x9e, 0xef, 0xdd, 0xd1, 0xb6, 0x9e, 0xef, 0x9d,
0x00, 0x01, 0x00, 0xc2, 0x03, 0x00, 0x00, 0xd2,
0xb5, 0xa8, 0xeb, 0x03, 0xb5, 0x28, 0xd2, 0xb6,
0xad, 0xeb, 0x03, 0xb6, 0x28, 0xde, 0xd2, 0xb6,
0x9f, 0xf0, 0xde, 0xd2, 0xb7, 0x9f, 0xf0, 0x9e,
0x28, 0xc0, 0x03, 0x02, 0x08, 0x06, 0x00, 0x0f,
0x0e, 0x10, 0x1b, 0x1a, 0x8d, 0x01, 0x66, 0x75,
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
Expand All @@ -38,8 +38,8 @@ const uint8_t qjsc_fib_module[282] = {
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d,
0x20, 0x31, 0x29, 0x20, 0x2b, 0x20, 0x66, 0x69,
0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29,
0x3b, 0x0a, 0x7d, 0x08, 0xea, 0x05, 0xbf, 0x00,
0xe1, 0x29, 0x06, 0x2e, 0xc0, 0x03, 0x01, 0x01,
0x3b, 0x0a, 0x7d, 0x08, 0xeb, 0x05, 0xc0, 0x00,
0xe2, 0x29, 0x06, 0x2f, 0xc0, 0x03, 0x01, 0x01,
0x00, 0x00,
};

Expand All @@ -61,13 +61,13 @@ const uint8_t qjsc_hello_module[183] = {
0x00, 0xc4, 0x03, 0x00, 0x00, 0x0c, 0x20, 0xfa,
0x01, 0xa2, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
0x00, 0x32, 0x00, 0xc4, 0x03, 0x00, 0x0c, 0x08,
0xea, 0x02, 0x29, 0x38, 0xe3, 0x00, 0x00, 0x00,
0x42, 0xe4, 0x00, 0x00, 0x00, 0x04, 0xe5, 0x00,
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x38, 0xe3,
0x00, 0x00, 0x00, 0x42, 0xe4, 0x00, 0x00, 0x00,
0x04, 0xe6, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
0xbc, 0x0a, 0xef, 0x24, 0x02, 0x00, 0x0e, 0x06,
0x2e, 0xc0, 0x03, 0x01, 0x01, 0x08, 0x18, 0x28,
0xeb, 0x02, 0x29, 0x39, 0xe3, 0x00, 0x00, 0x00,
0x43, 0xe4, 0x00, 0x00, 0x00, 0x04, 0xe5, 0x00,
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x39, 0xe3,
0x00, 0x00, 0x00, 0x43, 0xe4, 0x00, 0x00, 0x00,
0x04, 0xe6, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00,
0xbd, 0x0a, 0xf0, 0x24, 0x02, 0x00, 0x0e, 0x06,
0x2f, 0xc0, 0x03, 0x01, 0x01, 0x08, 0x18, 0x28,
0x36, 0x17, 0x62, 0x00, 0x2a, 0x20, 0x00,
};

Expand Down
Loading

0 comments on commit 5b609f1

Please sign in to comment.