Skip to content

Commit f326a7a

Browse files
authoredApr 19, 2024
Add strip option in qjsc to reduce object size (#388)
- `-s` strips the source code - `-ss` strips source and line/column numbers information - `qjsc repl.js` generates an object size of **105726** bytes - `qjsc -s repl.js` generates an object size of **20853** bytes - `qjsc -ss repl.js` generates an object size of only **16147** bytes - compile repl.js with `-ss` - bump byte code version to 12
1 parent 43dc65d commit f326a7a

9 files changed

+1362
-12529
lines changed
 

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ clean:
6161
cmake --build $(BUILD_DIR) --target clean
6262

6363
codegen: $(QJSC)
64-
$(QJSC) -o gen/repl.c -m repl.js
64+
$(QJSC) -ss -o gen/repl.c -m repl.js
6565
$(QJSC) -e -o gen/function_source.c tests/function_source.js
6666
$(QJSC) -e -o gen/hello.c examples/hello.js
6767
$(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js

‎gen/function_source.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const uint32_t qjsc_function_source_size = 384;
66

77
const uint8_t qjsc_function_source[384] = {
8-
0x0b, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
8+
0x0c, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
99
0x6c, 0x02, 0x66, 0x30, 0x74, 0x65, 0x73, 0x74,
1010
0x73, 0x2f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
1111
0x6f, 0x6e, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63,
@@ -15,12 +15,12 @@ const uint8_t qjsc_function_source[384] = {
1515
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20,
1616
0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65,
1717
0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20,
18-
0x7d, 0x0c, 0x00, 0x02, 0x01, 0x9e, 0x01, 0x00,
18+
0x7d, 0x0c, 0x00, 0xfa, 0x01, 0x9e, 0x01, 0x00,
1919
0x06, 0x00, 0x03, 0x00, 0x01, 0xa0, 0x01, 0x06,
2020
0xa0, 0x01, 0x00, 0x00, 0x00, 0xb2, 0x03, 0x02,
2121
0x00, 0x30, 0xb4, 0x03, 0x04, 0x00, 0x70, 0xb2,
2222
0x03, 0x04, 0x03, 0x70, 0x10, 0x00, 0x01, 0x00,
23-
0xe0, 0x01, 0x00, 0x01, 0x00, 0x0c, 0x43, 0x02,
23+
0xe0, 0x01, 0x00, 0x01, 0x00, 0x0c, 0x43, 0xfa,
2424
0x01, 0xb4, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00,
2525
0x00, 0x03, 0x00, 0xbb, 0x2a, 0x28, 0xb6, 0x03,
2626
0x03, 0x01, 0x04, 0x02, 0x1e, 0x0c, 0x0e, 0x1a,

‎gen/hello.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
const uint32_t qjsc_hello_size = 89;
66

77
const uint8_t qjsc_hello[89] = {
8-
0x0b, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
8+
0x0c, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
99
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
1010
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
1111
0x6c, 0x64, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70,
1212
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
13-
0x6f, 0x2e, 0x6a, 0x73, 0x0c, 0x00, 0x02, 0x00,
13+
0x6f, 0x2e, 0x6a, 0x73, 0x0c, 0x00, 0xfa, 0x00,
1414
0x9e, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00,
1515
0x14, 0x01, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x38,
1616
0xd9, 0x00, 0x00, 0x00, 0x42, 0xda, 0x00, 0x00,

‎gen/hello_module.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
const uint32_t qjsc_fib_module_size = 310;
66

77
const uint8_t qjsc_fib_module[310] = {
8-
0x0b, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
8+
0x0c, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
99
0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62, 0x5f,
1010
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x6a,
1111
0x73, 0x06, 0x66, 0x69, 0x62, 0x02, 0x6e, 0x0d,
1212
0xb2, 0x03, 0x00, 0x01, 0x00, 0x00, 0xb4, 0x03,
13-
0x00, 0x00, 0x0c, 0x20, 0x02, 0x01, 0x9e, 0x01,
13+
0x00, 0x00, 0x0c, 0x20, 0xfa, 0x01, 0x9e, 0x01,
1414
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x09, 0x00,
15-
0xb4, 0x03, 0x00, 0x01, 0x0c, 0x43, 0x02, 0x01,
15+
0xb4, 0x03, 0x00, 0x01, 0x0c, 0x43, 0xfa, 0x01,
1616
0xb4, 0x03, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00,
1717
0x1a, 0x01, 0xb6, 0x03, 0x00, 0x01, 0x00, 0xb4,
1818
0x03, 0x00, 0x00, 0xd0, 0xb3, 0xa7, 0xe9, 0x03,
@@ -49,7 +49,7 @@ const uint8_t qjsc_fib_module[310] = {
4949
const uint32_t qjsc_hello_module_size = 177;
5050

5151
const uint8_t qjsc_hello_module[177] = {
52-
0x0b, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
52+
0x0c, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
5353
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
5454
0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
5555
0x2e, 0x6a, 0x73, 0x1e, 0x2e, 0x2f, 0x66, 0x69,
@@ -60,7 +60,7 @@ const uint8_t qjsc_hello_module[177] = {
6060
0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x10,
6161
0x66, 0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d,
6262
0x0d, 0xb2, 0x03, 0x01, 0xb4, 0x03, 0x00, 0x00,
63-
0x01, 0x00, 0xb6, 0x03, 0x00, 0x0c, 0x20, 0x02,
63+
0x01, 0x00, 0xb6, 0x03, 0x00, 0x0c, 0x20, 0xfa,
6464
0x01, 0x9e, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
6565
0x00, 0x32, 0x00, 0xb6, 0x03, 0x00, 0x0c, 0x08,
6666
0xe9, 0x02, 0x29, 0x38, 0xdc, 0x00, 0x00, 0x00,

0 commit comments

Comments
 (0)