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

Do headers translation only once #113

Merged
merged 1 commit into from
Nov 22, 2018

Conversation

pushkarnk
Copy link
Contributor

Translating HTTPHeaders to HeadersContainer is an inevitable and expensive task. Given that the HTTPHeaders from HTTPRequestHead will not change, the translation could be a one-time thing. Currently, we do the translation everytime the headers property is accessed. We could do an eager translation in the initializer or a lazy translation when the property is accessed for the first time. Given that Kitura will most likely access the headers at least once, an eager translation shouldn't be a problem here.

public var headers : HeadersContainer {
return HeadersContainer.create(from: _headers)
}
public var headers : HeadersContainer

private var _headers: HTTPHeaders
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have _headers as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

The only place where we use is to get Host. Can we now re-use headers.httpHeader() to obtain the same if it is not expensive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nethraravindran Yes, I agree. I've made the change.

Translating HTTPHeaders to HeadersContainer is an inevitable and expensive task. Given that the HTTPHeaders from HTTPRequestHead will not change, the translation could be a one-time thing. Currently, we do the translation everytime the `headers` property is accessed. We could do an eager translation in the initializer or a lazy translation when the property is accessed for the first time. Given that Kitura will most likely access the headers at least once, an eager translation shouldn't be a problem here.
@pushkarnk pushkarnk merged commit c895b61 into Kitura:master Nov 22, 2018
@pushkarnk pushkarnk deleted the headers-translation branch March 11, 2019 19:30
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