-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
ChatGPT4 experiment for Opal coding #2541
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New version includes separate methods for generating the names definition and the names assignments, and for generating the sexp in the two different situations. The comments are preserved and expanded to give more context on what each part of the code is doing. (ChatGPT4)
Broken it down into several smaller functions, each handling one specific part of the transformation process. I've also added more detailed comments and improved variable names to increase readability. (ChatGPT4)
Current Proc#call implementation has several conditional branches and a try/catch block, all of which might impact performance. The main logic is to call a block, and the exceptional scenarios are when $$brk or $$ret is thrown. The current implementation always checks for these exceptions which could be avoided in the common case. An optimized version that reduces the amount of branching and avoids setting up a try/catch block unless needed. In this version, we've factored out the invocation of a proc or a lambda into helper functions $call_proc and $call_lambda. In each function, we set up the try/catch block only if necessary (i.e., if $$brk or $$ret is present). In Proc#call, we simply check if a block is passed and attach it to the proc. Then we delegate to the appropriate function based on whether the proc is a lambda. The main goal of this refactor is to streamline the common path and remove unnecessary branching and exception handling overhead. (ChatGPT4) $ bundle exec rake bench:ips FILE=benchmark-ips/bm_block_vs_yield.rb before: block: 3033756.5 i/s - 1.30x slower after: block: 3272548.5 i/s - 1.26x slower The difference is small, but tangible and resulting code looks much cleaner.
Instead of using a for...in loop to convert arguments into an array, I've used Array.prototype.slice.call(arguments). This is more efficient and performs better. (ChatGPT 3.5) before: method missing 2.354M (± 0.3%) i/s - 11.781M in 5.003958s after: method missing 2.447M (± 1.2%) i/s - 12.372M in 5.057387s
(ChatGPT4)
Pre-allocate the memory for the result array, which can help performance when dealing with very large hashes. Pre-allocating memory is beneficial because it prevents the JavaScript engine from having to continuously resize the array as elements are added. In this version, we create an array with a predefined size (equal to the number of keys in the hash) using new Array(length). Then, instead of pushing elements into the array, we assign each key-value pair directly to the corresponding index in the result array. (ChatGPT4)
In this version, we're using new Array(length) to create an array with a size equal to the input array. This preallocates the required memory for the array. Then, instead of pushing each element into the array, we're assigning the values directly to the corresponding index in the result array. (ChatGPT4)
The new version is based on semantics of MRI implementation of Range#size and is rewritten in JavaScript. (ChatGPT4)
elia
approved these changes
Jun 15, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍👍
Lint should be ok when merging
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I will expand the description later on.