Avoid allocating for each binding trigger #5490
Open
+33
−27
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.
Description:
This reworks data listeners for bindings to be a bit smarter. Instead of using a map (with unnecessary bool parameter) to store the listener, we just use a regular slice. We iterate over this slice in the queued operation without needing to append to a new slice first. Delete is a bit more expensive (and more code because with don't use Go 1.21 yet and can't use the
slices
package) but add is the one that is more common and trigger is the most common so it makes sense to optimise for the common path. A second lock is needed to not deadlock tests for some reason and it also avoids contention between value updates.Checklist: