Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Store header values as byte[] #169

Closed
benaadams opened this issue Aug 19, 2015 · 8 comments
Closed

Store header values as byte[] #169

benaadams opened this issue Aug 19, 2015 · 8 comments
Assignees
Milestone

Comments

@benaadams
Copy link
Contributor

Encode and store the header values as byte[] at the point they are added to the header dictionary { set }; encoding back to string if read by user code { get }; and using the byte[] when output to the socket (alternate IEnumerable interface?).

As strings are immutable this wouldn't break user code; to change the header the value would need to be set again. Response headers aren't read back that much by user code; oauth does it; but oauth is generally slow anyway.

This would mean the server header would only need to be encoded once for the lifetime and date only encoded once per second, rather than both on every response.

Additionally it would move the encoding time out of the socket write path which may improve throughput?

More of a suggestion than something backed up by hard metrics.

@Tratcher
Copy link
Member

FYI: This probably conflicts with the coming change from string[] to StringValues :aspnet/HttpAbstractions#361

@benaadams
Copy link
Contributor Author

Actually aspnet/HttpAbstractions#361 might make it easier as that puts the indirection in place?

@DamianEdwards
Copy link
Member

Yep this is something that could be supported by StringValues.

@benaadams
Copy link
Contributor Author

This has been more or less addressed

@benaadams benaadams reopened this Nov 11, 2015
@benaadams
Copy link
Contributor Author

Reopening this in light of #367 though would probably want some kind of HasBytes type of flag which could just be HasBytes => _valueBytes == null; then switch between using that or converting the string; e.g. keep it in the version it was set as.

Would likely want the byte[] version to be automatically converted and cached as string or string[] when used as such, but not auto conversion to byte[] as that would likely be memory inefficient.

For an example use, in benchmarks ContentType and Content-Length could be set to a static byte[]

/cc @davidfowl

@muratg
Copy link
Contributor

muratg commented Dec 21, 2015

@CesarBS could you check if this is done already? Feel free to ping @JunTaoLuo and @Tratcher

@Tratcher
Copy link
Member

Tratcher commented Jan 4, 2016

dotnet/extensions#68

@JunTaoLuo
Copy link
Contributor

Will be addressed in the PR mentioned above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants