-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall/js: allocate makeArgs slices on stack #49799
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
Conversation
@@ -580,4 +604,5 @@ func CopyBytesToJS(dst Value, src []byte) int { | |||
return n | |||
} | |||
|
|||
//go:noescape |
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.
Justification: this will affect whether byte slices with dynamic contents but statically known length to not escape anymore. It is correct because the bytes are copied to JS, not referenced by JS
@@ -292,6 +293,7 @@ func (v Value) Get(p string) Value { | |||
return r | |||
} | |||
|
|||
//go:noescape |
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.
Justification: this (and the one on valueSet
and valueDelete
) will affect whether strings with dynamic contents but statically known length to not escape anymore. It is correct, because the Go memory is only accessed for the duration of the call.
@@ -209,6 +209,7 @@ func ValueOf(x interface{}) Value { | |||
} | |||
} | |||
|
|||
//go:noescape |
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.
Justification: this will affect whether strings with dynamic contents but statically known length to not escape anymore. It is correct, because the string is immediately copied away from Go memory on the JS side.
This PR (HEAD: 8c960c1) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/367045 to see it. Tip: You can toggle comments from me using the |
@@ -391,13 +410,15 @@ func (v Value) Call(m string, args ...interface{}) Value { | |||
return makeValue(res) | |||
} | |||
|
|||
//go:noescape |
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.
Justification: this (and the one on valueInvoke
and valueNew
) is essential for the slice optimization. It is correct because the slices are not kept around.
Message from Go Bot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/367045. |
Message from Hajime Hoshi: Patch Set 1: Run-TryBot+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/367045. |
Message from Go Bot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/367045. |
Message from Go Bot: Patch Set 1: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/367045. |
Message from Hajime Hoshi: Patch Set 1: Code-Review+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/367045. |
This is superseded by #66684 🚀 |
This change optimizes the
syscall/js
package such that:syscall/js
features with slices and strings of statically-known length will not cause them to be escaped to the heap, at least with the current Go compilerThere should be no observable difference in the
syscall/js
API.These changes have been discussed and mostly agreed upon in the linked issue.
Fixes #39740
I am aware that this change falls outside a release cycle and during a development freeze. I will leave it up to maintainers to decide whether this qualifies for a freeze exception.