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

Map enhancement #144

Merged
merged 1 commit into from
Jun 14, 2023
Merged

Map enhancement #144

merged 1 commit into from
Jun 14, 2023

Conversation

EagleTw
Copy link
Collaborator

@EagleTw EagleTw commented Jun 8, 2023

The enhancement information as GitHub page - rb_bench.
Correctness tested is provided.
Issue #29

@EagleTw EagleTw force-pushed the map_enhancement branch 3 times, most recently from a4c11da to e641047 Compare June 8, 2023 13:43
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Squash the commits and emphasize the benefits of this proposed change.

@sysprog21 sysprog21 deleted a comment from EagleTw Jun 8, 2023
@jserv
Copy link
Contributor

jserv commented Jun 8, 2023

You shall utilize __UNREACHABLE when possible. See https://github.com/sysprog21/rv32emu/blob/master/src/common.h

@jserv
Copy link
Contributor

jserv commented Jun 12, 2023

Let's synchronize with the implementation in rbtree_bench.

@EagleTw
Copy link
Collaborator Author

EagleTw commented Jun 12, 2023

I may need to rewrite a good commit message.
Need some time.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Exclude the generated map.h.gch (pre-compiled header).

{
node->parent_color = (unsigned long) parent | color;
return (map_node_t *) (((uintptr_t) node->right_red) & ~3);
Copy link
Contributor

Choose a reason for hiding this comment

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

Evaluate torvalds/linux@b0687c1 and integrate into this pull request (as another commit).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not think it is a good idea.

In linux the usage rb_set_black is only used to set node from red to black.
However, the map rb_node_set_red we implemented can set node from any state to black.
If we change the interface, we will cause a lot of unneeded branch that hurts the performance.

@jserv
Copy link
Contributor

jserv commented Jun 12, 2023

I may need to rewrite a good commit message. Need some time.

Useful prompts for ChatGPT:

  • Proofread the git commit message "..."
  • Write in third-person point of view
  • Wrap the body of git commit messages at 72 characters

@EagleTw EagleTw force-pushed the map_enhancement branch 3 times, most recently from 803047f to 85c87cf Compare June 12, 2023 09:36
@EagleTw EagleTw force-pushed the map_enhancement branch 3 times, most recently from e385b4b to 2498bce Compare June 12, 2023 13:33
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Revise the git commit message as How to Write a Git Commit Message suggested.

  1. Do not end the subject line with a period
  2. Use the body to explain what and why vs. how

You shall describe the experimental environment where you perform.

@jserv
Copy link
Contributor

jserv commented Jun 13, 2023

Revise the git commit message as How to Write a Git Commit Message suggested.

Append the folowing:

This map implementation has undergone extensive modifications, heavily relying on the rb.h header file from jemalloc.
The original rb.h file served as the foundation and source of inspiration for adapting and tailoring it specifically for this map implementation.
Therefore, credit and sincere thanks are extended to jemalloc for their invaluable work.
Reference: https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/rb.h

@EagleTw EagleTw force-pushed the map_enhancement branch 2 times, most recently from 70efb84 to 6fb4448 Compare June 13, 2023 15:24
The performance of block_insert and block_find operations in rv32emu
experiences significant improvements when replacing the original map
with the proposed map implementation.

The proposed map implementation shows significant improvements over the
original version. The following data represents the average time of
20 experiments, each involving the insertion, finding, and deletion of
10 million randomly generated nodes in a random order.

  OpType   |  Insert (ns)  | Find (ns)   | Remove (ns)
  ---------+---------------+-------------+------------
  original |  824,515,450  | 21,132,350  | 925,074,950
  proposed |  535,518,250  | 10,032,300  | 602,755,100
  improved |         35 %  |       52 %  |        35 %

  Heap memory usage also improved by 17 %.

This map implementation has undergone extensive modifications, heavily
relying on the rb.h header file from jemalloc. The original rb.h file
served as the foundation and source of inspiration for adapting and
tailoring it specifically for this map implementation.
Therefore, credit and sincere thanks are extended to jemalloc for
their invaluable work.
Reference:
https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/rb.h
@jserv jserv merged commit 434c466 into sysprog21:master Jun 14, 2023
@jserv
Copy link
Contributor

jserv commented Jun 14, 2023

Thank @ypaskell for contributing!

2011eric pushed a commit to 2011eric/rv32emu that referenced this pull request Jul 22, 2023
The proposed map implementation demonstrates substantial improvements
compared to the original one by replacing it with a faster red-black
tree. The data provided below represents the average time of 20
experiments, each involving the insertion, finding, and deletion of
10 million randomly generated nodes in a random order. These tests were
conducted on Apple M1 Pro.

  OpType   |  Insert (ns)  | Find (ns)   | Remove (ns)
  ---------+---------------+-------------+------------
  original |  824,515,450  | 21,132,350  | 925,074,950
  proposed |  535,518,250  | 10,032,300  | 602,755,100
  ---------+---------------+-------------+------------
  improved |         35 %  |       52 %  |        35 %

Heap memory usage has also been reduced by 17%.

This map implementation has undergone extensive modifications, heavily
relying on the rb.h header file from jemalloc. The original rb.h file
served as the foundation and source of inspiration for adapting and
tailoring it specifically for this map implementation.
Therefore, credit and sincere thanks are extended to jemalloc for
their invaluable work.

Reference:
https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/rb.h
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
The proposed map implementation demonstrates substantial improvements
compared to the original one by replacing it with a faster red-black
tree. The data provided below represents the average time of 20
experiments, each involving the insertion, finding, and deletion of
10 million randomly generated nodes in a random order. These tests were
conducted on Apple M1 Pro.

  OpType   |  Insert (ns)  | Find (ns)   | Remove (ns)
  ---------+---------------+-------------+------------
  original |  824,515,450  | 21,132,350  | 925,074,950
  proposed |  535,518,250  | 10,032,300  | 602,755,100
  ---------+---------------+-------------+------------
  improved |         35 %  |       52 %  |        35 %

Heap memory usage has also been reduced by 17%.

This map implementation has undergone extensive modifications, heavily
relying on the rb.h header file from jemalloc. The original rb.h file
served as the foundation and source of inspiration for adapting and
tailoring it specifically for this map implementation.
Therefore, credit and sincere thanks are extended to jemalloc for
their invaluable work.

Reference:
https://github.com/jemalloc/jemalloc/blob/dev/include/jemalloc/internal/rb.h
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