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

Create developer's guide for performance enhancements #928

Closed
YamatoSecurity opened this issue Feb 18, 2023 · 9 comments · Fixed by #958
Closed

Create developer's guide for performance enhancements #928

YamatoSecurity opened this issue Feb 18, 2023 · 9 comments · Fixed by #958
Assignees
Labels
documentation Improvements or additions to documentation Priority:Low

Comments

@YamatoSecurity
Copy link
Collaborator

YamatoSecurity commented Feb 18, 2023

I would like to create some documentation about Rust performance for future developers as well as Rust programmers interested in making their programs very fast and memory efficient.
We can put it under doc/RustPerformance-English.md and doc/RustPerformance-Japanese.md.
@fukusuket Could I ask you to write the first draft? (No hurry, so whenever you have extra time.)
You can just document all of your performance enhancements you made recently in Japanese and I can handle the English translations when it is finished.
I would like to include the old sample code versus new sample code and roughly how much it improves speed and/or memory.
Maybe group by category. For example:

  1. Avoid regular expressions as much as possible. Here are some ways that we filter with String comparisons first, etc..
  2. Use Iterators instead of Vec.
    Iterators can reduce memory usage because memory allocation only occurs one record at a time.
    Also, change the return type to Box to make Iterator the return value of the function.
    Iterator is trait (not structs), so need to be wrapped in a Box to return from a function
  3. Avoid using clone
  4. Use compactstr to avoid heap allocation
  5. Use mimalloc for Windows, xxx for linux/mac
  6. etc...

What do you think?

@YamatoSecurity YamatoSecurity added documentation Improvements or additions to documentation Priority:Low labels Feb 18, 2023
@fukusuket
Copy link
Collaborator

fukusuket commented Feb 18, 2023

That's sounds nice :) I'd love to write a draft document 💪
I'd start by sorting through the recent performance improvements.

Also, it would be better to be able to describe how to measure performance? (heaptrack, mimalloc-stats, memory layout ... etc)

@YamatoSecurity
Copy link
Collaborator Author

@fukusuket Thank you so much! I will assign you then.
Indeed, we should probably explain how we are measuring performance. Recently I have been putting my benchmarks in your pull requests and noting them in the changelog as well. We can use your or my benchmarks. I don't think it has to be perfect measurements. Just as long as we give people an idea of how much performance changed in our project.

@fukusuket
Copy link
Collaborator

fukusuket commented Feb 18, 2023

memo:

Category of performance improvement

Memory

by removing unnecessary fields and string

by reducing clone() and to_string()

by using iterator instead of vec

by using external crate

by changing global memory allocator(mimalloc)

Speed

by reducing IO process

by changing regex match to std:string method match

by changing global memory allocator(mimalloc)

by changing buffrerd IO

by chacheing regex

by using multithread

Benchmarking

Reference

Rust performance guide

enum vs trait

@fukusuket
Copy link
Collaborator

@YamatoSecurity
I'm starting to write a performance guide on this branch.
I'm thinking of writing with the above structure,🤔 what do you think? I would appreciate it if you could comment if there is anything that should be changed in the paragraph. 🙏 (It's still a draft of a draft, so anything can be changed :) )

@YamatoSecurity
Copy link
Collaborator Author

@fukusuket Looks great!
What about changing the order from 1. メモリ使用量の削減 2. 速度の改善 3. ベンチマークの取得 to 1. 速度の改善 2. メモリ使用量の削減 3. ベンチマークの取得 ?
I think this might be better as most people want to hear about speed improvements first and 2 & 3 go together more. (reducing memory and checking with benchmarks)
Everything else looks great.
It would be nice to have a screenshot of the mimalloc --debug output and explain which numbers are the most important and how the latest version of mimalloc seems to have a bug that gives results like -128GB but just to ignore that as MS needs to fix it.

@fukusuket
Copy link
Collaborator

fukusuket commented Feb 26, 2023

Thank you for reviewing :) I'll update the order paragraphs and put a screenshot!
I'm still working on it, so if you have any other suggestions, feel free to let me know 💪

@fukusuket
Copy link
Collaborator

@YamatoSecurity
I have finished writing the Japanese version of the draft document on this branch :)
I would appreciate it if you could do a review and an English translation when you have time🙏

@YamatoSecurity
Copy link
Collaborator Author

@fukusuket Thank you so much! It might take a little while as I have to prepare for teaching SANS next week but can definitely do it after that.

@hitenkoku Can you add whatever performance advice you have as well?

@hitenkoku
Copy link
Collaborator

@fukusuket Thank you for writing. It is very useful for me.

@YamatoSecurity I have nothing to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Priority:Low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants