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

builtin: speed up string concatenation and repeat() method with vmemcpy #18206

Merged

Conversation

i582
Copy link
Contributor

@i582 i582 commented May 19, 2023

instead of for loop for copying data

These changes almost do not speed up the program with the -prod flag, since modern С compilers can do such optimization on their own, but in normal mode, the performance gain is from 1.6 (concatenation) to 1.8 (repeat) times.

Concatenation:
Old (`for` loop):
Time (mean):          3.699 s +- 0.071 s  [User: 3.629 s, System: 0.069 s]
Range (min ... max):  3.548 s ... 3.741 s  10 runs

New (vmemcpy):
Time (mean):          2.305 s +- 0.065 s  [User: 2.263 s, System: 0.041 s]
Range (min ... max):  2.172 s ... 2.355 s  10 runs

`vmemcpy version` ran 1.60 +- 0.05 times faster than 'for loop version'

🤖 Generated by Copilot at 7ea5db3

Refactor the string module to use a faster and clearer memory copying function. This affects vlib/builtin/string.v and its tests.

🤖 Generated by Copilot at 7ea5db3

  • Replace manual byte copying loops with vmemcpy calls to improve performance and readability of string operations (link, link) in vlib/builtin/string.v

…mcpy instead of `for` loop for copying data

These changes almost do not speed up the program with the `-prod` flag,
since modern С compilers can do such optimization on their own, but in
normal mode, the performance gain is from 1.6 (concatenation) to 1.8 (repeat) times.

Concatenation:
Old (`for` loop):
Time (mean):          3.699 s +- 0.071 s  [User: 3.629 s, System: 0.069 s]
Range (min ... max):  3.548 s ... 3.741 s  10 runs

New (vmemcpy):
Time (mean):          2.305 s +- 0.065 s  [User: 2.263 s, System: 0.041 s]
Range (min ... max):  2.172 s ... 2.355 s  10 runs

`vmemcpy version` ran 1.60 +- 0.05 times faster than 'for loop version'
@i582 i582 changed the title builtin: speed up string concatenation and repeat() method with vme mcpy builtin: speed up string concatenation and repeat() method with vmemcpy May 19, 2023
@ArtemkaKun
Copy link
Contributor

Maybe your PR covers #276 ?

@i582
Copy link
Contributor Author

i582 commented May 19, 2023

Maybe your PR covers #276 ?

It seems not, it suggests optimizing several concatenations in a row in order to allocate memory only once

@i582 i582 requested a review from spytheman May 19, 2023 12:38
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 a39c265 into vlang:master May 19, 2023
l1mey112 pushed a commit to l1mey112/v that referenced this pull request Jun 7, 2023
…mcpy instead of `for` loop for copying data (vlang#18206)

These changes almost do not speed up the program with the `-prod` flag,
since modern С compilers can do such optimization on their own, but in
normal mode, the performance gain is from 1.6 (concatenation) to 1.8 (repeat) times.

Concatenation:
Old (`for` loop):
Time (mean):          3.699 s +- 0.071 s  [User: 3.629 s, System: 0.069 s]
Range (min ... max):  3.548 s ... 3.741 s  10 runs

New (vmemcpy):
Time (mean):          2.305 s +- 0.065 s  [User: 2.263 s, System: 0.041 s]
Range (min ... max):  2.172 s ... 2.355 s  10 runs

`vmemcpy version` ran 1.60 +- 0.05 times faster than 'for loop version'
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.

3 participants