Skip to content

Generate wrappers & use cgo hints#5

Closed
oliverbestmann wants to merge 5 commits into
mainfrom
cgo-hints
Closed

Generate wrappers & use cgo hints#5
oliverbestmann wants to merge 5 commits into
mainfrom
cgo-hints

Conversation

@oliverbestmann
Copy link
Copy Markdown
Owner

Using #cgo noescape and #cgo nocallback when possible allows the go compiler to pass pointers to heap values. This leads to it not needing to allocate when calling into wgpu. It only needs to allocate once for the returned wrapper object.

Before:

BenchmarkCreateView-10         	  630223	      1758 ns/op	      96 B/op	       3 allocs/op
BenchmarkCreateBindGroup-10    	  290613	      3642 ns/op	      32 B/op	       2 allocs/op
BenchmarkBeginRenderPass-10    	   32133	     44466 ns/op	     112 B/op	       6 allocs/op

After:

BenchmarkCreateView-10         	 1609491	       785.6 ns/op	      16 B/op	       1 allocs/op
BenchmarkCreateBindGroup-10    	  270481	      3702 ns/op	      16 B/op	       1 allocs/op
BenchmarkBeginRenderPass-10    	   27547	     36898 ns/op	      64 B/op	       3 allocs/op

…ations to reduce memory allocation & cgo overhead
…ious implementation was capturing the generic runtime info when creating the closure passed to SetFinalizer. This is not necessary if we use an interface.
@oliverbestmann
Copy link
Copy Markdown
Owner Author

@rcoreilly if you could have a quick look and check that nothing breaks on your side, that would be great. Otherwise I'll merge it later today or tomorrow and cleanup the pieces later :)

Comment thread wgpu/string-view.go Outdated

func (v stringView) Release() {
C.free(unsafe.Pointer(v.view.data))
if v.view.data {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if v.view.data != nil

This doesn't even compile!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yea I fixes that already. Sorry for that. One of those: "okay everything works. Let me create a PR. Wait, let me add this one if here and then push it"

@rcoreilly
Copy link
Copy Markdown

Yep everything seems to work in cogentcore!

@oliverbestmann
Copy link
Copy Markdown
Owner Author

Thanks. I'll have a look at why it doesn't compile in Mac and wasm in ci later today and continue with the approach.

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