14 Commits
Author SHA1 Message Date
Fabian Fett 6aff14dae9 Add inlinables (#149)
### Motivation

We want to have fast code.

### Changes

Add `@inlinable` to a number of functions, to allow better compiler
optimizations.

### Result

Improvements in some benchmarks
2026-09-01 16:09:13 +02:00
Mathias QuinteroandFabian Fett f41c097554 Improve Performance of HTTPField.value (#146)
### Motivation

When instantiating new HTTPFields, the values need to be validated,
legalized and turned into the internal representation.
We use this representation to expose a string in `HTTPField.value` as
well as to iterate over raw bytes using
`HTTPField.withUnsafeBytesOfValue`.

Currently the internal representation is to use a ISO Latin 1 String to
store the bytes only once. This however means that we need to transcode
back and forth for non ascii values, which causes a lot of extra
computations and allocations.

### Modifications

1. Moved logic to a standalone structure for `HTTPField.Value` rather
than `ISOLatin1String`
2. Added Unit Tests and Benchmarks
3. Swapped internal storage of values to be an enum of either a string
or a value
4. Whenever the bytes stored are valid utf8, we will not always store
the value as a raw string. This means that we need the least amount of
allocations and transcoding when operating with the value through our
public API
5. We only store a raw array of bytes whenever the bytes are not valid
utf8. This speeds up `withUnsafeBytesOfValue` massively and
`HTTPField.value` a little bit
6. During legalization, store the modified bytes in a temporary buffer
instead of using lazy collections to avoid allocating an array and speed
up utf8 validation
7. Use spans whenever possible to speed up access to bytes without
boundary checks

### Result

These are the changes on the benchmarks added in this PR

```
HTTPField-asciiBytesValueRoundTrip
Instructions: 28K -> 6847 (-75%)
Malloc: 1 -> 1

HTTPField-asciiValueRoundTrip
Instructions: 7367 -> 3081 (-58%)
Malloc: 0 -> 0

HTTPField-invalidAsciiBytesValueRoundTrip
Instructions: 133K -> 7255 (-94%)
Malloc: 6 -> 1 (-83%)

HTTPField-invalidAsciiBytesValueRoundTripAsLenientValue
Instructions: 62K -> 6623 (-89%)
Malloc: 3 -> 1 (-66%)

HTTPField-invalidAsciiValueRoundTrip
Instructions: 93K -> 6959 (-92%)
Malloc: 5 -> 1 (-80%)

HTTPField-invalidNonASCIIValueRoundTrip
Instructions: 393K -> 8735 (-97%)
Malloc: 11 -> 1 (-91%)

HTTPField-nonASCIIValueRoundTrip
Instructions: 131K -> 3219 (-97%)
Malloc: 4 -> 0 (-100%)
```

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2026-08-31 11:30:56 +02:00
Mathias Quintero c6bd833124 Improve Performance for HTTPField.Name Initializers (#144)
# Motivation

Currently when initializing a Field Name, we create a canonical
lowercased version of the field name. However, it is reasonable to
expect that a significant amount of the time the users will insert a
name string that is already lowercased, so turning it into lowercase
creates an extra unnecessary allocation

# Changes

This changes the validation step for the name to compute in a single
pass whether the name is valid and if it's already in the canonical
lowercased format. If it's already lowercased, then we can skip the
extra allocation and just reuse the same string. if it's valid but not
lowercased we can default to the previous logic.

For ultimate performance this iterates over Spans whenever we use Swift
6.4. For other Swift versions, we default to iterating over the UTF8View
instead, which is slightly slower, but keeps us backwards compatible.

# Result

More performance
2026-08-25 15:51:28 +02:00
Guoye Zhang 141600d7e6 Adopt availability macros (#127) 2026-06-22 15:16:29 -07:00
Guoye Zhang db774a277f Support embedded Swift (#116)
In order for swift-http-api-proposal to support embedded Swift,
swift-http-types has to support embedded Swift first.
2026-06-05 10:54:44 -07:00
Guoye Zhang 0fd14cc0fc Check that the decoded field value string is actually ISOLatin1 (#126)
The decoder assumes that the string is within the ISOLatin1 range
without checking, potentially allowing invalid values to be saved in an
HTTPField

rdar://178437865
2026-06-03 19:25:45 +01:00
Franz Busch f3d9ec3eef [CI] Make all CI checks green
# Motivation

We just adopted GH actions and want to make sure all the CI checks are green.

# Modification

This PR makes the necessary changes to pass all checks. Including:

- Adding a licenseignore file
- Moving `swift-format` and adopting the config that we use in all other swift on server repos.

# Result

Green CI.
2024-10-24 22:30:18 +02:00
Guoye Zhang c8357002a1 Update comment 2024-04-24 10:37:47 -07:00
Guoye Zhang 20d5ed91ae Support lenient legalization of header field values 2024-04-23 17:31:54 -07:00
Guoye Zhang 43107b6de1 Update contributors 2023-09-19 12:24:27 -07:00
Guoye Zhang e885fa315c Remove custom DecodingError and harden fields 2023-08-08 13:39:37 -07:00
Guoye Zhang 792abeab1f Support Codable 2023-08-07 18:09:53 -07:00
Guoye Zhang ae848811f9 Internal API review feedback 2023-06-30 10:06:35 -07:00
Guoye Zhang c164739694 Import code 2023-06-30 10:06:35 -07:00