Motivation:
Swift started using posix_memalign very recently (Jan 2019) so we need
to hook that too to get correct results.
Modifications:
Hook posix_memalign, reallocf & valloc
Result:
alloc tests should pass again
Motivation:
The name `mapIfError` implied that you can transform the error value but
really that's never what it did. Instead, it allowed you to recover
from a failure.
Modifications:
- rename `mapIfError` to `recover`
Result:
cleaner method names
Motivation:
EventLoopPromise.succeed/fail has extraneous labels that don't add
anything but noise.
Modifications:
remove extraneous labels
Result:
less noise in the code
Motivation:
ELF's API should be as close as possible to the new Result's API.
Therefore, we should rename `then` to `flatMap`
Modifications:
- renamed `then` to `flatMap`
- renamed `thenIfError` to `flatMapError`
- renamed ELF's generic parameter from `T` to `Value`
Result:
- more like Result
- fixes#688
Motivation:
DispatchData's APIs are less than optimal and the current one we used
did allocate at least on Linux to copy bytes out.
Modifications:
introduce ByteBuffer.write/read/set/getDispatchData
Result:
when Dispatch gets fixed, lower allocations
Motivation:
We had to disable the allocation test because of a SwiftPM bug which is
now fixed.
Modifications:
re-enable the allocation tests
Result:
more tests == better
Motivation:
NIO2 development starts now.
Modifications:
Made NIO Swift 5-only for everything else see docs/public-api-changes-NIO1-to-NIO2.md
Result:
NIO2 development can start.
Motivation:
making a promise of a type is more grammatical than making a promise for
a type.
Modifications:
s/newPromise(for/newPromise(of/g
Result:
more grammar
Motivation:
When creating new promises I always find it very frustrating to type the
`: EventLoopPromise<Type>` type annotation but it's necessary for the
compiler to know type the promise will be fulfilled with.
Modifications:
allow an optional `for: SomeType.self` parameter for `newPromise` as
let p = eventLoop.newPromise(for: Int.self)
is much easier to type than
let p: EventLoopPromise<Int> = eventLoop.newPromise()
Result:
easier to write code
Motivation:
Unsafe(Mutable)RawBufferPointers have a few APIs that make our code
easier to reason about. In this PR I'm trying to introduce some of it.
Modifications:
Improved UnsafeRawBufferPointer usage
Result:
code easier to reason about which hopefully leads to fewer bugs. Also:
In many cases we now get free bounds checking in debug mode, yay :).
Motivation:
We should be consistent with naming and also choose descriptive names.
Modifications:
- Deprecate old init method that uses numThreads
- Add new init with numberOfThreads param name
- Everywhere use the new init
Result:
More consistent and descriptive naming. Fixes https://github.com/apple/swift-nio/issues/432.
Motivation:
Many uses of atomics restrict themselves to using atomic variables within
objects that already have reference semantics (i.e. classes) and have
appropriate lifetime management. In this case, the current NIO Atomic
performs an unnecessary heap allocation in order to get itself a reference
count that it can use to free the underlying heap memory.
This is an unnecessary allocation that can often be elided, especially in
situations where many such atomics may be needed. Thus, we should provide
the ability to manually manage the lifetime of the heap-allocated memory for
the atomic, and change some uses of it in our codebase to reduce overhead.
Modifications:
1. Moved most of the code of Atomic to a new struct, UnsafeEmbeddedAtomic.
2. Reimplemented Atomic in terms of UnsafeEmbeddedAtomic.
3. Updated EventLoopFuture to use an UnsafeEmbeddedAtomic for isFulfilled.
Result:
1/3 as many allocations per EventLoopFuture.
Motivation:
We had a few issues with ByteBuffer methods allocating without us
knowing, the only way to make sure we don't regress is obviously a test.
Modifications:
add a ByteBuffer allocation counter test
Result:
less room for regressions.
Motivation:
The ping/pong test should only do 4 allocations:
- readFromSocket does unconditionally allocate one ByteBuffer
(allocating one ByteBuffer does 2 allocations)
- we have a ping and a pong side, each call readFromSocket
so 2 * 2 = 4 allocations per message. Before adding the `@_inlineable`
to the read/write/get/set integer methods in ByteBuffer however I was
seeing way more allocations. So looked at them and fixed them.
Turns out that massively reduces the number of allocations for HTTP too.
On Linux I was seeing this change:
1000_reqs_1_conn: 282000 -> 70000
1_reqs_1000_conn: 1287000 -> 907000
Modifications:
- made the ByteBuffer integer methods inlineable
- added a test that makes sure we don't regress on the simplest possible
use of NIO: a ping/pong server
Result:
After your change, what will change.
Motivation:
Sometimes it's useful if the integration tests can output something that
isn't always useful. `-v` for verbose is way too verbose so this adds a
`-i` flag to the integration tests that lets 'info' messages through.
Modifications:
- add `-i` flags to integration tests
- make use of it in the integration counter tests
Result:
if we enable `-i` in CI, then we can constantly monitor the number of
allocations we do even if we don't fail the tests.
Motivation:
The allocation counter integration tests previously used a pretty crude
malloc implementation for the case that malloc is needed whilst we
resolve malloc from libc using dlsym. This implements a much better
version and also allows us to actually use free. Previously we just
leaked all the memory (which is okay as its just a test but in
constrained environments this wouldn't scale as we might actually run
out of memory). The reason we used to leak the memory is that given a
pointer we couldn't figure out if that pointer was alloated using libc's
malloc or our crude malloc implementation so we didn't know how to free.
The new version fixes that as all the pointers vended from
recursive_malloc live in one global block. That makes it trivial to
check if a given pointer is allocated by recursive_malloc (lives in that
block) or libc's malloc (doesn't live in the recursive_malloc block).
Modifications:
- implemented a better recursive_malloc function
- make the allocation counter test actually free memory that can be
freed
Result:
Less memory use in the allocation counter test.
Motivation:
In shell, subshells don't inherit the shell flags (such as `set -eu`)
and therefore need to set them again. The allocation counter test uses a
subshell but forgot to `set -eu` in the subshell.
Modifications:
`set -eu` in the subshell for the allocation counter tests.
Result:
if there's an error building the test program the test now fails.
Motivation:
We have code running on multiple threads and certain allocations/frees
happen for example after a promise has been fulfilled. We can't
deterministically wait for that so the only thing we can do is sleep a
little and wait...
Modifications:
Added a 100ms delay after an allocation counted test run.
Result:
Hopefully we don't see this again:
["total_allocations": 322051, "remaining_allocations": 24], ["total_allocations": 322051, "remaining_allocations": -24]
where the first test run had 24 allocations that weren't freed and the
second one on the other hand had 24 frees for allocations that "didn't
happen"...
Motivation:
Memory leaks are rare in Swift but they can happen. If we run a
realistic workload and the number of `malloc`s and `free`s is very close
to 0, we can be fairly sure we didn't have any (too bad) leaks.
Therefore this adds a simple leaks detector.
Modifications:
Add a leak detector.
Result:
We should now detect leaks even if the total number of allocations
doesn't increase.
Motivation:
In Swift, it's really easy to accidentally add allocations yet the
number of allocations is really important for performance.
Therefore it's useful to have an integration test that counts the number
of allocations and compares them to a reference (and fails if the number
of allocations increases).
Modifications:
- add an allocation counter
- add a HTTP1 client/server example that is run with the allocation
counter intrumentation
Result:
We should now be able to track the number of allocations.