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

reorganize code, little bit faster #509

Merged
merged 1 commit into from
Jan 21, 2024
Merged

reorganize code, little bit faster #509

merged 1 commit into from
Jan 21, 2024

Conversation

abeobk
Copy link
Contributor

@abeobk abeobk commented Jan 20, 2024

Check List:

  • Tests pass (./test.sh <username> shows no differences between expected and actual outputs)
  • All formatting changes by the build are committed
  • Your launch script is named calculate_average_<username>.sh (make sure to match casing of your GH user name) and is executable
  • Output matches that of calculate_average_baseline.sh
  • For new entries, or after substantial changes: When implementing custom hash structures, please point to where you deal with hash collisions (line number)

Standard set
Benchmark 1: ./calculate_average_abeobk.sh
Time (mean ± σ): 736.2 ms ± 17.3 ms [User: 18932.3 ms, System: 722.9 ms]
Range (min … max): 716.6 ms … 767.5 ms 10 runs

10k set
Benchmark 1: ./calculate_average_abeobk.sh
Time (mean ± σ): 1.848 s ± 0.022 s [User: 49.804 s, System: 0.985 s]
Range (min … max): 1.816 s … 1.889 s 10 runs

@@ -330,13 +330,16 @@ public static void main(String[] args) throws InterruptedException, IOException
}

if (SHOW_ANALYSIS) {
System.out.println("total=" + Arrays.stream(lenhist).sum());
System.out.println("length_histogram = "
debug("Collision stat: ");
Copy link
Owner

Choose a reason for hiding this comment

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

Just to be sure: does your implementation guarantee to handle collisions 100% correctly? Or can there be a (however small) risk for unhandled collisions and thus incorrect results? I suppose it's the former.

Copy link
Contributor Author

@abeobk abeobk Jan 21, 2024

Choose a reason for hiding this comment

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

Yes it is handled correctly (with the assumptions given in the 1brc description).
Since there are only10k stations at most, the hash table size is intentionally added 10000, so there is no need to mod the table size. The performance gains was achieved by using a fast + low collision mixer ( 0 collision for standard set, still low for 10k set, I had some fun tweaking this function :) ) and by removing lots of unnecessary branching.

Copy link
Owner

Choose a reason for hiding this comment

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

Got it, thx.

@gunnarmorling
Copy link
Owner

Nice, 00:02.336 now!

Benchmark 1: timeout -v 300 ./calculate_average_abeobk.sh 2>&1
  Time (mean ± σ):      2.336 s ±  0.006 s    [User: 15.820 s, System: 0.701 s]
  Range (min … max):    2.329 s …  2.343 s    5 runs

Summary
  abeobk: trimmed mean 2.3362541187466674, raw times 2.3407769550800004,2.32911485408,2.3351161250800003,2.3429942460800004,2.3328692760800003

Leaderboard

| # | Result (m:s.ms) | Implementation     | JDK | Submitter     | Notes     |
|---|-----------------|--------------------|-----|---------------|-----------|
|   | 00:02.336 | [link](https://github.com/gunnarmorling/1brc/blob/main/src/main/java/dev/morling/onebrc/CalculateAverage_abeobk.java)| 21.0.1-graal | [Van Phu DO](https://github.com/abeobk) | GraalVM native binary |

@gunnarmorling gunnarmorling merged commit 410425c into gunnarmorling:main Jan 21, 2024
1 check 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