-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
x.json2.decoder2: full support to struct attributes #22741
x.json2.decoder2: full support to struct attributes #22741
Conversation
What is |
Previous solutions had rules, related to attributes, scattered throughout encode_value/decode_value.Now, the rules are distributed across other functions, each with its own responsibility. Which reduces the maintenance "cost". And it leaves more freedom for the user, in case they want to implement a new feature that they think is cool and that has not been developed by the json library. It also allows other libraries to create support for other attributes, such as email and phone numbers validators... ,without much effort and without affecting performance too much. |
The maintenance cost, of code that uses indirection and reflection is higher (when it breaks). That can be offset by simpler usages. I do not see good ones in this PR yet. Please provide concrete examples, of code that will be simplified. |
Before [latest V] (faster)V cache folder /home/hitalo/.vmodules/.cache was wiped.
V tmp.c and tests folder folder /tmp/v_1000 was wiped.
Starting benchmark...
max_iterations: 1000000
***Structure and maps***
SPENT 340.470 ms in decoder2.decode[Stru](json_data)!
SPENT 482.235 ms in old_json.decode(Stru, json_data)!
SPENT 387.807 ms in decoder2.decode[SumTypes](json_data)!
SPENT 509.426 ms in old_json.decode(SumTypes, json_data)!
SPENT 90.053 ms in decoder2.decode[StructType[string]](json_data1)!
SPENT 94.422 ms in old_json.decode(StructType[string], json_data1)!
SPENT 90.643 ms in decoder2.decode[StructTypeOption[string]](json_data1)!
SPENT 93.809 ms in old_json.decode(StructTypeOption[string], json_data1)!
SPENT 58.014 ms in decoder2.decode[StructType[int]](json_data2)!
SPENT 100.996 ms in old_json.decode(StructType[int], json_data2)!
SPENT 193.633 ms in decoder2.decode[map[string]string](json_data1)!
SPENT 193.691 ms in old_json.decode(map[string]string, json_data1)!
***arrays***
SPENT 325.138 ms in decoder2.decode[[]int]('[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
SPENT 565.424 ms in old_json.decode([]int, '[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
***simple types***
SPENT 20.355 ms in decoder2.decode[int]('2')!
SPENT 17.608 ms in decoder2.decode[bool]('true')!
SPENT 53.068 ms in decoder2.decode[time.Time]('2022-03-11T13:54:25')!
SPENT 87.921 ms in decoder2.decode[string]('"abcdefghijklimnopqrstuv"')!
***alias***
SPENT 19.488 ms in decoder2.decode[IntAlias](2)!
SPENT 89.537 ms in decoder2.decode[StringAlias]('"abcdefghijklimnopqrstuv"')!
***Sumtypes***
SPENT 73.181 ms in decoder2.decode[SumTypes](2)!
SPENT 134.789 ms in decoder2.decode[SumTypes]('"abcdefghijklimnopqrstuv"')! Now [This PR] SlowerV cache folder /home/hitalo/.vmodules/.cache was wiped.
V tmp.c and tests folder folder /tmp/v_1000 was wiped.
Starting benchmark...
max_iterations: 1000000
***Structure and maps***
SPENT 435.348 ms in decoder2.decode[Stru](json_data)!
SPENT 481.752 ms in old_json.decode(Stru, json_data)!
SPENT 502.539 ms in decoder2.decode[SumTypes](json_data)!
SPENT 502.240 ms in old_json.decode(SumTypes, json_data)!
SPENT 116.154 ms in decoder2.decode[StructType[string]](json_data1)!
SPENT 91.710 ms in old_json.decode(StructType[string], json_data1)!
SPENT 127.106 ms in decoder2.decode[StructTypeOption[string]](json_data1)!
SPENT 91.615 ms in old_json.decode(StructTypeOption[string], json_data1)!
SPENT 79.565 ms in decoder2.decode[StructType[int]](json_data2)!
SPENT 99.632 ms in old_json.decode(StructType[int], json_data2)!
SPENT 199.808 ms in decoder2.decode[map[string]string](json_data1)!
SPENT 199.536 ms in old_json.decode(map[string]string, json_data1)!
***arrays***
SPENT 331.909 ms in decoder2.decode[[]int]('[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
SPENT 571.260 ms in old_json.decode([]int, '[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
***simple types***
SPENT 19.737 ms in decoder2.decode[int]('2')!
SPENT 17.488 ms in decoder2.decode[bool]('true')!
SPENT 53.500 ms in decoder2.decode[time.Time]('2022-03-11T13:54:25')!
SPENT 82.150 ms in decoder2.decode[string]('"abcdefghijklimnopqrstuv"')!
***alias***
SPENT 19.824 ms in decoder2.decode[IntAlias](2)!
SPENT 80.840 ms in decoder2.decode[StringAlias]('"abcdefghijklimnopqrstuv"')!
***Sumtypes***
SPENT 63.274 ms in decoder2.decode[SumTypes](2)!
SPENT 130.163 ms in decoder2.decode[SumTypes]('"abcdefghijklimnopqrstuv"')! |
After merge on latest master V cache folder /home/hitalo/.vmodules/.cache was wiped.
V tmp.c and tests folder folder /tmp/v_1000 was wiped.
Starting benchmark...
max_iterations: 1000000
***Structure and maps***
SPENT 404.889 ms in decoder2.decode[Stru](json_data)!
SPENT 460.689 ms in old_json.decode(Stru, json_data)!
SPENT 479.434 ms in decoder2.decode[SumTypes](json_data)!
SPENT 494.619 ms in old_json.decode(SumTypes, json_data)!
SPENT 110.415 ms in decoder2.decode[StructType[string]](json_data1)!
SPENT 89.593 ms in old_json.decode(StructType[string], json_data1)!
SPENT 119.058 ms in decoder2.decode[StructTypeOption[string]](json_data1)!
SPENT 87.923 ms in old_json.decode(StructTypeOption[string], json_data1)!
SPENT 73.912 ms in decoder2.decode[StructType[int]](json_data2)!
SPENT 94.753 ms in old_json.decode(StructType[int], json_data2)!
SPENT 183.044 ms in decoder2.decode[map[string]string](json_data1)!
SPENT 183.367 ms in old_json.decode(map[string]string, json_data1)!
***arrays***
SPENT 311.392 ms in decoder2.decode[[]int]('[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
SPENT 553.583 ms in old_json.decode([]int, '[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
***simple types***
SPENT 19.128 ms in decoder2.decode[int]('2')!
SPENT 17.133 ms in decoder2.decode[bool]('true')!
SPENT 52.787 ms in decoder2.decode[time.Time]('2022-03-11T13:54:25')!
SPENT 84.898 ms in decoder2.decode[string]('"abcdefghijklimnopqrstuv"')!
***alias***
SPENT 19.005 ms in decoder2.decode[IntAlias](2)!
SPENT 83.076 ms in decoder2.decode[StringAlias]('"abcdefghijklimnopqrstuv"')!
***Sumtypes***
SPENT 59.625 ms in decoder2.decode[SumTypes](2)!
SPENT 125.958 ms in decoder2.decode[SumTypes]('"abcdefghijklimnopqrstuv"')! |
Co-authored-by: Delyan Angelov <[email protected]>
Look at this simple solution for dealing with attributes and not having to worry about new attributes that are in fashion.
Huly®: V_0.6-21188