Skip to content

Conversation

@glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Dec 2, 2019

Motivation:

Percent encoding and decoding go via Foundation so we really get a
bridges CFString.

Modifications:

Implement the percent encoding and decoding without Foundation.

Result:

  • Less Obj-C
  • A small perf gain when encoding/decoding status messages:
    • before: percent_encode_decode_10k_status_messages: 67,63,62,63,65,62,63,65,63,63
    • after: percent_encode_decode_10k_status_messages: 49,43,43,43,43,43,43,45,44,44

@glbrntt glbrntt requested a review from MrMage December 2, 2019 15:34
@glbrntt
Copy link
Collaborator Author

glbrntt commented Dec 2, 2019

See also #644

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

FYI, here is a blazing-fast HTML-escaping routine in case you want to try optimizing this further: https://github.com/vapor/template-kit/blob/master/Sources/TemplateKit/Utilities/HTMLEscape.swift

(At least pre-Swift-5.1, I was unable to get similar performance without using unsafe methods.)

Motivation:

Percent encoding and decoding go via Foundation so we really get a
bridges CFString.

Modifications:

Implement the percent encoding and decoding without Foundation.

Result:

- Less Obj-C
- A small perf gain when encoding/decoding status messages:
  - before: percent_encode_decode_10k_status_messages: 67,63,62,63,65,62,63,65,63,63
  - after: percent_encode_decode_10k_status_messages: 49,43,43,43,43,43,43,45,44,44
@glbrntt glbrntt force-pushed the gb-status-marshalling branch from a94907e to eb818b0 Compare December 3, 2019 17:01
@glbrntt
Copy link
Collaborator Author

glbrntt commented Dec 3, 2019

Thanks for that @MrMage! I added the length-check fast path since I reckon that's very common and a pretty big win:

percent_encode_decode_10k_status_messages: 51,48,49,48,49,49,48,47,48,47
percent_encode_decode_10k_ascii_status_messages: 14,14,14,15,14,14,14,14,14,14

@glbrntt glbrntt requested a review from MrMage December 4, 2019 10:12
Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

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

Do we have tests that ensure the correctness of the algorithm?

@glbrntt
Copy link
Collaborator Author

glbrntt commented Dec 4, 2019

@glbrntt
Copy link
Collaborator Author

glbrntt commented Dec 4, 2019

Admittedly there aren't many of them though.

@MrMage
Copy link
Collaborator

MrMage commented Dec 4, 2019

Thanks! I must have missed those.

LGTM from my side.

@glbrntt glbrntt merged commit a27e85b into grpc:nio Dec 4, 2019
@glbrntt glbrntt deleted the gb-status-marshalling branch December 4, 2019 11:29
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