bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.59k stars 327 forks source link

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

Open rts-gordon opened 6 months ago

rts-gordon commented 6 months ago

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

AsterDY commented 6 months ago

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

rts-gordon commented 6 months ago

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
 }
AsterDY commented 6 months ago

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.

rts-gordon commented 6 months ago

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

image

AsterDY commented 6 months ago

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

rts-gordon commented 5 months ago

Hi there, Any update for this issue?

f3oall commented 5 months ago

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

nightwolfz commented 5 months ago

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

AsterDY commented 5 months ago

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