-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
chore(stdlib): Optimize List.join
#2130
chore(stdlib): Optimize List.join
#2130
Conversation
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.
Looks pretty good so far, just needs a few tweaks!
stdlib/list.gr
Outdated
} | ||
} | ||
@unsafe | ||
let rec iterBuildString = ( |
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.
Could we call this something like joinHelp
or buildJoinedString
?
stdlib/list.gr
Outdated
use DataStructures.{ stringSize } | ||
match (lst) { | ||
[] => void, | ||
// Last Element |
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.
// Last Element | |
// Last element |
stdlib/list.gr
Outdated
let size = stringSize(ptr) | ||
Memory.copy(offset, ptr + 8n, size) | ||
}, | ||
// Regular Path |
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.
// Regular Path |
stdlib/list.gr
Outdated
Memory.copy(offset, ptr + 8n, size) | ||
let offset = offset + size | ||
Memory.copy(offset, sepPtr, sepSize) | ||
iterBuildString(strPtr, sepPtr, sepSize, offset + sepSize, tl) |
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.
iterBuildString(strPtr, sepPtr, sepSize, offset + sepSize, tl) | |
iterBuildString(strPtr, sepPtr, sepSize, offset + sepSize, tl) | |
ignore(hd) |
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.
I should put the ignore
above the function call right otherwise it wont be a tail call?
stdlib/list.gr
Outdated
use DataStructures.{ allocateString, stringSize } | ||
let sepPtr = WasmI32.fromGrain(separator) | ||
let sepSize = stringSize(sepPtr) | ||
let strSize = iterSize(sepSize, 0n - sepSize, list) |
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.
With the changes I suggested this would just be 0n
.
stdlib/list.gr
Outdated
let sepPtr = WasmI32.fromGrain(separator) | ||
let sepSize = stringSize(sepPtr) | ||
let strSize = iterSize(sepSize, 0n - sepSize, list) | ||
if (strSize <= 0n) return "" |
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.
And this check wouldn't be needed.
Those changes have been commited. |
This pr optimizes
List.join
similarly to howArray.join
was optimized in #1948, this change makesList.join
use only a single allocation, and should reduce the number of times we need to copy while reallocating.Closes: #728