Skip to content
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

windows: dynamically adjust the buffer size #5

Merged
merged 1 commit into from
Jul 27, 2020
Merged

Conversation

nicks
Copy link
Member

@nicks nicks commented Jul 27, 2020

Hello @jazzdan,

Please review the following commits I made in branch nicks/bufsize:

56f2b1e (2020-07-27 15:05:09 -0400)
windows: dynamically adjust the buffer size

Code review reminders, by giving a LGTM you attest that:

  • Commits are adequately tested
  • Code is easy to understand and conforms to style guides
  • Incomplete code is marked with TODOs
  • Code is suitably instrumented with logging and metrics

@nicks nicks requested a review from jazzdan July 27, 2020 19:05
}
go w.readEvents()
return w, nil
}

func (w *Watcher) SetBufferSize(bufSize int) {
Copy link

Choose a reason for hiding this comment

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

Where does this get called?

Copy link
Member Author

Choose a reason for hiding this comment

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

i plan to call it from the tilt code!

e := syscall.ReadDirectoryChanges(watch.ino.handle, &watch.buf[0],
uint32(unsafe.Sizeof(watch.buf)), w.recursive, mask, nil, &watch.ov, 0)

hdr := (*reflect.SliceHeader)(unsafe.Pointer(&watch.buf))
Copy link

Choose a reason for hiding this comment

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

Not sure what's going on here 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

In Go, a slice is implemented as

  • a pointer to some memory
  • a length field
  • a capacity field

https://golang.org/pkg/reflect/#SliceHeader

The windows syscall is all C. It needs a pointer to memory. So we unpack the slice, and pull the memory pointer out.

it's conceptually not that hard, but Go REALLY doesn't want you to do this (because it starts to mess with the Go garbage collector), so the syntax is pretty awkward

Copy link

Choose a reason for hiding this comment

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

ahh got it, that makes sense!

@nicks nicks merged commit 991e307 into master Jul 27, 2020
@nicks nicks deleted the nicks/bufsize branch July 27, 2020 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants