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

Use known and adaptive buffer sizes to lower generated garbage #117

Merged
merged 10 commits into from
Jun 14, 2024
Merged

Conversation

cee-dub
Copy link
Collaborator

@cee-dub cee-dub commented Jun 13, 2024

Closes #101

To enable merging this branch, we verified which of the following hostcalls fully support adaptive buffers (return a buflen error with a usable value) in both ExecuteD and Viceroy:

ExecuteD:

  • fastly_http_req method_get
  • fastly_http_req uri_get
  • fastly_dictionary get (partial!) Full support needs new hostcall that returns the needed size
  • fastly_geo lookup
  • fastly_secret_store plaintext
  • fastly_device_detection lookup
  • fastly_cache get_user_metadata
  • fastly_http_req downstream_tls_client_hello

Viceroy:

  • fastly_device_detection lookup
  • fastly_dictionary get (partial!) Full support needs new hostcall that returns the needed size
  • fastly_http_req method_get
  • fastly_http_req uri_get
  • fastly_geo lookup
  • fastly_secret_store plaintext
  • fastly_cache get_user_metadata (❌ not implemented in viceroy)
  • fastly_http_req downstream_tls_client_hello (❌ not implemented in viceroy)

Any hostcalls found not to match behavior between ExecuteD and Viceroy will be corrected in Viceroy.

Any hostcalls found not to return a useable value in ExecuteD will be held back in a separate branch until a new version is fully rolled to the fleet.

@cee-dub cee-dub self-assigned this Jun 13, 2024
@cee-dub cee-dub requested review from joeshaw and lpereira June 13, 2024 04:25
Copy link
Member

@joeshaw joeshaw left a comment

Choose a reason for hiding this comment

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

This mostly looks good to me, thanks for taking it on. I have a few minor comments below.

internal/abi/fastly/hostcalls_guest.go Outdated Show resolved Hide resolved
internal/abi/fastly/hostcalls_guest.go Show resolved Hide resolved
internal/abi/fastly/hostcalls_guest.go Outdated Show resolved Hide resolved
internal/abi/fastly/hostcalls_guest.go Outdated Show resolved Hide resolved
@joeshaw
Copy link
Member

joeshaw commented Jun 13, 2024

This would address #101 btw.

@joeshaw
Copy link
Member

joeshaw commented Jun 13, 2024

Due to the failing device detection test, there's something not working as expected with adaptive buffers.

Specifically: I thought that buf.NValue() would report the size of the buffer needed to hold the full value, if the passed buffer was too short. Instead it always equals 0.

It's possible the device detection code doesn't support adaptive buffers. Probably an oversight.

@joeshaw
Copy link
Member

joeshaw commented Jun 13, 2024

Due to the failing device detection test, there's something not working as expected with adaptive buffers.
Specifically: I thought that buf.NValue() would report the size of the buffer needed to hold the full value, if the passed buffer was too short. Instead it always equals 0.

It's possible the device detection code doesn't support adaptive buffers. Probably an oversight.

Looks like a bug in Viceroy: https://github.com/fastly/Viceroy/blob/main/lib/src/wiggle_abi/device_detection_impl.rs#L46-L51

Note how n_written is not set to the expected size of the buffer.

Contrast this with the equivalent secret store code: https://github.com/fastly/Viceroy/blob/main/lib/src/wiggle_abi/secret_store_impl.rs#L105-L114

It doesn't appear to be an issue with the production Compute platform though.

@joeshaw
Copy link
Member

joeshaw commented Jun 13, 2024

fastly/Viceroy#383 adds adaptive buffer support for geolocation and device detection to Viceroy, which should allow these tests to pass once it's merged and a new Viceroy is released.

@lpereira
Copy link
Contributor

I like these changes! From a cursory glance I didn't see anything obviously wrong, just the minor nits I pointed above.

@cee-dub cee-dub marked this pull request as ready for review June 14, 2024 16:36
@elliottt
Copy link
Contributor

I've verified on the ExecuteD side that all the host calls (except for fastly_dictionary#get) will populate the length needed outparam. Additionally, the two Viceroy host calls that you mentioned being unsure about (fastly_cache#get_user_metadata and fastly_http_req#downstream_tls_client_hello) are both currently unimplemented.

@cee-dub cee-dub merged commit 5dfc9df into main Jun 14, 2024
10 checks passed
@cee-dub cee-dub deleted the cw/buflen branch June 14, 2024 16:43
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.

Use adaptive buffers everywhere
4 participants