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

improved 2nd and final submission #685

Merged
merged 1 commit into from
Feb 1, 2024
Merged

Conversation

yourwass
Copy link
Contributor

  • eliminated memory allocations on the hot path
  • used serkan-ozal's trick to exclude munmap from timings

Check List:

  • You have run ./mvnw verify and the project builds successfully
  • 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): 216
  • Execution time:
  • Execution time of reference implementation:

Comment on lines +24 to +25
eval "exec 3< <({ java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_yourwass; })"
read <&3 result
Copy link
Owner

Choose a reason for hiding this comment

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

What's the purpose of this eval and read construct here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well copy pasting in a hurry, copies bad code. Although the idea is good, the implementation by serkan-ozal that I copied was sloppy.
All the eval things and opening a 3rd file descriptor are not really needed. The code is equivalent to and has the same timings with:

read result < <( java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_yourwass )
echo -e "$result"  

Now, to explain this: read reads one line from the output of the java program that is redirected into the variable result, that's it. It just doesn't wait for a second line, or whatever the java program does afterwards. It immediately prints the result. Thus, also the System.out.close() in the java code, is not really needed.

The unneeded eval evaluates the string. When it does, it opens a 3rd file descriptor and redirects the output of the java command onto it. Then the read reads from that file descriptor one line into the variable result.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, got it. Neat trick :)

@gunnarmorling gunnarmorling merged commit 75bece5 into gunnarmorling:main Feb 1, 2024
1 check passed
@gunnarmorling
Copy link
Owner

00:02.557 now. Thx for particpating in 1BRC and congrats on creating one of the fastest entries!

@gunnarmorling
Copy link
Owner

Hey @yourwass!

Congrats again on being in the Top 20 of the One Billion Row Challenge!

To celebrate this amazing achievement, I would like to send you a 1BRC t-shirt and coffee mug. To claim your prize, fill out this form by Feb 18. After submitting the form, please provide a comment with the random value you've specified in the form, so that I know it is you who submitted it.

All data entered will solely be used in relation to processing this shipment. Shipments can be sent to any country listed here or here (I'll use whichever one is cheaper for me to ship to your location). A big thank you to Decodable for sponsoring these prizes!

Thanks a lot for participating in 1BRC,

--Gunnar

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