Skip to content
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: use Linked List data structure strategy #22581

Merged
merged 14 commits into from
Oct 19, 2024

Conversation

enghitalo
Copy link
Contributor

@enghitalo enghitalo commented Oct 19, 2024

changes

  • Improve performance between 50% and 200%
  • Replace array and node to only LinkedList
  • decode string
  • decode map
  • decode array
  • decode time

Benchmarks

 ./v wipe-cache && ./v -prod -cc gcc crun vlib/x/json2/decoder2/tests/bench.v 
 
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   349.628 ms in decoder2.decode[Stru](json_data)!
 SPENT   369.915 ms in old_json.decode(Stru, json_data)!

 SPENT    99.198 ms in decoder2.decode[StructType[string]](json_data1)!
 SPENT    92.955 ms in old_json.decode(StructType[string], json_data1)!

 SPENT   121.837 ms in decoder2.decode[StructTypeOption[string]](json_data1)!
 SPENT   143.498 ms in old_json.decode(StructTypeOption[string], json_data1)!

 SPENT    64.695 ms in decoder2.decode[StructType[int]](json_data2)!
 SPENT    88.690 ms in old_json.decode(StructType[int], json_data2)!

 SPENT   209.812 ms in decoder2.decode[map[string]string](json_data1)!
 SPENT   183.958 ms in old_json.decode(map[string]string, json_data1)!


***arrays***
 SPENT   313.657 ms in decoder2.decode[[]int]('[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!
 SPENT   551.574 ms in old_json.decode([]int, '[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]')!


***simple types***
 SPENT    20.992 ms in decoder2.decode[int]('2')!
 SPENT    19.372 ms in decoder2.decode[bool]('true')!
 SPENT   738.004 ms in decoder2.decode[time.Time]('2022-03-11T13:54:25')!
 SPENT    90.998 ms in decoder2.decode[string]('"abcdefghijklimnopqrstuv"')!

@enghitalo enghitalo changed the title Jso2/new decode2 rewrite x.json2.decoder2: use Linked List data structure strategy Oct 19, 2024
@spytheman
Copy link
Member

Please solve the conflict, by rebasing on master or merging.

@enghitalo enghitalo force-pushed the jso2/new-decode2-rewrite branch from a7eb134 to 46997be Compare October 19, 2024 07:53
@spytheman
Copy link
Member

Thank you.

`n` { .null }
else { .unknown }
fn get_value_kind(value u8) ValueKind {
// value := *val
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment, it is useless

Comment on lines +60 to +69
mut result_buffer := []u8{}
mut current := list.head
for current != unsafe { nil } {
value_kind_as_string := current.value.value_kind.str()
unsafe { result_buffer.push_many(value_kind_as_string.str, value_kind_as_string.len) }
result_buffer << u8(` `)

current = current.next
}
return result_buffer.bytestr()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a string builder, not a private implementation of it, that will be harder to understand in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think buffer less complex than strings builder and not needs import strings

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@spytheman spytheman merged commit 9ed3788 into vlang:master Oct 19, 2024
66 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants