sonic icon indicating copy to clipboard operation
sonic copied to clipboard

Execute file size is too big, can sonic be optimized when compile?

Open rts-gordon opened this issue 2 years ago • 9 comments

Hi there, Sonic is a great json library, high performance and very easy to use, thanks for your work.

But the execute file size is double, it is can‘t acceptable in my scenario. Can sonic be optimized when compile? for example: only compile source code for CPU/OS arch currently in use, maybe this will reduce execute file size.

Thank you.

image

rts-gordon avatar Jan 17 '24 06:01 rts-gordon

Ok, I will try it. First investigate where the binary comes from. If you already have stats on it, it will help a lot

AsterDY avatar Jan 17 '24 07:01 AsterDY

Those are my project execute files, two methods for json parsing, Windows 10, CPU Intel Core i7.

method1: json parse, execute file size: 48M

 if err := json.Unmarshal(msg, &account); err != nil {
 	log.Errorf("Unmarshal account failed, tenant: %s, platform: %s, error: %s, message: %s", tenant, platform, err.Error(), msg)
 	return
 }

method 2: sonic parse, execute file size: 97M

if err := sonic.Unmarshal(msg, &account); err != nil {
 	log.Errorf("Unmarshal account failed, tenant: %s, platform: %s, error: %s, message: %s", tenant, platform, err.Error(), msg)
 	return
 }

rts-gordon avatar Jan 17 '24 21:01 rts-gordon

Can you try to use older version (<1.10) and give size? If it is still a lot, I doubt that the main cause it doesn't come from C asm files.

AsterDY avatar Jan 18 '24 17:01 AsterDY

@AsterDY There are three execute files size, the Sonic old version (<1.10) is normal, maybe version 1.10 changed something.

image

rts-gordon avatar Jan 18 '24 23:01 rts-gordon

ok,It seem native codes need to be embeded on demands. Let me try

AsterDY avatar Jan 22 '24 10:01 AsterDY

Hi there, Any update for this issue?

rts-gordon avatar Feb 01 '24 23:02 rts-gordon

Also, the compilation time is x2 for v1.10, on 1.9.2 it's two times faster.

f3oall avatar Feb 05 '24 20:02 f3oall

Might be useful https://github.com/bytedance/sonic/issues/561#issuecomment-1886061319

nightwolfz avatar Feb 07 '24 04:02 nightwolfz

Might be useful #561 (comment)

Seem it is due to v1.10 imported iasm as basic assembler (#393), which is used to reslove #489 meanwhile improve C-Go intercall performance. At present, no better solution for this. cc @chenzhuoyu

AsterDY avatar Feb 08 '24 07:02 AsterDY