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

[SR-10028] one single 'handler as? _ChannelOutboundHandler' allocates 144 times, every time it's executed #52431

Closed
weissi opened this issue Mar 1, 2019 · 6 comments
Assignees

Comments

@weissi
Copy link
Member

@weissi weissi commented Mar 1, 2019

Previous ID SR-10028
Radar None
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, Runtime
Assignee @eeckstein
Priority Medium

md5: 409597107c76088922e596aa9ce933ea

relates to:

  • SR-10709 Swift needs allocation counter tests

Issue Description:

I've got this simple program using NIO

import NIO
import NIOHTTP1

@inline(never)
public func blackhole(_ x: _ChannelOutboundHandler) {}

@inline(never)
func foo(handler: ChannelHandler) -> _ChannelOutboundHandler? {
    return handler as? _ChannelOutboundHandler
}

let h = ByteToMessageHandler(HTTPResponseDecoder())

for f in 0..<10_000 {
    blackhole(foo(handler: h)!)
}

with our new HTTP parser which uses conditional conformances. I wouldn't expect this program to allocate at all in the loop because the only thing executed is

handler as? _ChannelOutboundHandler

but in actual fact, it allocates 144 times per execution of the loop.

Repro:

  • download the attached repro.tar.gz

  • unpack

  • run

    swift build -c release && sudo dtrace -n '::BEGIN { mcalls = 0; } pid$target::malloc:entry { @ms[ustack()] = count(); mcalls += 1; } ::END { printa(@ms); printf("==========\ntotal malloc calls: %d\n", mcalls); }' -c ./.build/x86_64-apple-macosx/release/swiftslow
    

    output:

// [...] MANY MORE OF THESE BLOCKS, too many for this JIRA issue

              libsystem_malloc.dylib`malloc
              libc++abi.dylib`operator new(unsigned long)+0x28
              libswiftCore.dylib`std::__1::__hash_table<std::__1::__hash_value_type<(anonymous namespace)::SubstitutionEntry, unsigned int>, std::__1::__unordered_map_hasher<(anonymous namespace)::SubstitutionEntry, std::__1::__hash_value_type<(anonymous namespace)::SubstitutionEntry, unsigned int>, (anonymous namespace)::SubstitutionEntry::Hasher, true>, std::__1::__unordered_map_equal<(anonymous namespace)::SubstitutionEntry, std::__1::__hash_value_type<(anonymous namespace)::SubstitutionEntry, unsigned int>, std::__1::equal_to<(anonymous namespace)::SubstitutionEntry>, true>, std::__1::allocator<std::__1::__hash_value_type<(anonymous namespace)::SubstitutionEntry, unsigned int> > >::__rehash(unsigned long)+0x36
              libswiftCore.dylib`(anonymous namespace)::Remangler::addSubstitution((anonymous namespace)::SubstitutionEntry const&)+0x29a
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangleAnyNominalType(swift::Demangle::Node*)+0x307
              libswiftCore.dylib`swift::Demangle::mangleNode(swift::Demangle::Node* const&, llvm::function_ref<swift::Demangle::Node* (swift::Demangle::SymbolicReferenceKind, void const*)>)+0x118
              libswiftCore.dylib`_findNominalTypeDescriptor(swift::Demangle::Node*, swift::Demangle::Demangler&)+0x6c
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledNominalType(swift::Demangle::Node*, swift::TargetContextDescriptor<swift::InProcess> const*&, swift::TargetMetadata<swift::InProcess> const*&)+0xb9
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac8
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0x78f
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x486
            40000

              libsystem_malloc.dylib`malloc
              libc++abi.dylib`operator new(unsigned long)+0x28
              libswiftCore.dylib`void std::__1::vector<swift::Mangle::SubstitutionWord, std::__1::allocator<swift::Mangle::SubstitutionWord> >::__push_back_slow_path<swift::Mangle::SubstitutionWord>(swift::Mangle::SubstitutionWord&&)+0x9d
              libswiftCore.dylib`void swift::Mangle::mangleIdentifier<(anonymous namespace)::Remangler>((anonymous namespace)::Remangler&, llvm::StringRef)+0x389
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangle(swift::Demangle::Node*)+0x2e5a
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangleAnyNominalType(swift::Demangle::Node*)+0x2dc
              libswiftCore.dylib`swift::Demangle::mangleNode(swift::Demangle::Node* const&, llvm::function_ref<swift::Demangle::Node* (swift::Demangle::SymbolicReferenceKind, void const*)>)+0x118
              libswiftCore.dylib`_findNominalTypeDescriptor(swift::Demangle::Node*, swift::Demangle::Demangler&)+0x6c
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledNominalType(swift::Demangle::Node*, swift::TargetContextDescriptor<swift::InProcess> const*&, swift::TargetMetadata<swift::InProcess> const*&)+0xb9
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0x73c
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x486
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
            40000

              libsystem_malloc.dylib`malloc
              libc++abi.dylib`operator new(unsigned long)+0x28
              libswiftCore.dylib`void std::__1::vector<swift::TargetMetadata<swift::InProcess> const*, std::__1::allocator<swift::TargetMetadata<swift::InProcess> const*> >::__push_back_slow_path<swift::TargetMetadata<swift::InProcess> const* const&>(swift::TargetMetadata<swift::InProcess> const* const&&&)+0x9e
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0x7bf
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x486
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              swiftslow`foo(handler:)+0x21
              swiftslow`main+0xac
              libdyld.dylib`start+0x1
              swiftslow`0x1
            40000

              libsystem_malloc.dylib`malloc
              libswiftCore.dylib`swift::Demangle::Demangler::init(llvm::StringRef)+0x59
              libswiftCore.dylib`swift::Demangle::Demangler::demangleType(llvm::StringRef)+0x12
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x25f
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x120
              libswiftCore.dylib`(anonymous namespace)::DecodedMetadataBuilder::createBoundGenericType(swift::TargetContextDescriptor<swift::InProcess> const*, llvm::ArrayRef<swift::TargetMetadata<swift::InProcess> const*>, swift::TargetMetadata<swift::InProcess> const*) const+0x293
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xd70
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x486
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              swiftslow`foo(handler:)+0x21
              swiftslow`main+0xac
            40000

              libsystem_malloc.dylib`malloc
              libc++abi.dylib`operator new(unsigned long)+0x28
              libswiftCore.dylib`(anonymous namespace)::Remangler::addSubstitution((anonymous namespace)::SubstitutionEntry const&)+0x14a
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangle(swift::Demangle::Node*)+0x2e66
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangleAnyNominalType(swift::Demangle::Node*)+0x27c
              libswiftCore.dylib`swift::Demangle::mangleNode(swift::Demangle::Node* const&, llvm::function_ref<swift::Demangle::Node* (swift::Demangle::SymbolicReferenceKind, void const*)>)+0x118
              libswiftCore.dylib`_findNominalTypeDescriptor(swift::Demangle::Node*, swift::Demangle::Demangler&)+0x6c
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledNominalType(swift::Demangle::Node*, swift::TargetContextDescriptor<swift::InProcess> const*&, swift::TargetMetadata<swift::InProcess> const*&)+0xb9
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac8
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0x78f
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x486
            60000

              libsystem_malloc.dylib`malloc
              libc++abi.dylib`operator new(unsigned long)+0x28
              libswiftCore.dylib`void std::__1::vector<swift::Mangle::SubstitutionWord, std::__1::allocator<swift::Mangle::SubstitutionWord> >::__push_back_slow_path<swift::Mangle::SubstitutionWord>(swift::Mangle::SubstitutionWord&&)+0x9d
              libswiftCore.dylib`void swift::Mangle::mangleIdentifier<(anonymous namespace)::Remangler>((anonymous namespace)::Remangler&, llvm::StringRef)+0x389
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangle(swift::Demangle::Node*)+0x2e5a
              libswiftCore.dylib`(anonymous namespace)::Remangler::mangleAnyNominalType(swift::Demangle::Node*)+0x27c
              libswiftCore.dylib`swift::Demangle::mangleNode(swift::Demangle::Node* const&, llvm::function_ref<swift::Demangle::Node* (swift::Demangle::SymbolicReferenceKind, void const*)>)+0x118
              libswiftCore.dylib`_findNominalTypeDescriptor(swift::Demangle::Node*, swift::Demangle::Demangler&)+0x6c
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledNominalType(swift::Demangle::Node*, swift::TargetContextDescriptor<swift::InProcess> const*&, swift::TargetMetadata<swift::InProcess> const*&)+0xb9
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac8
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0x78f
              libswiftCore.dylib`swift::Demangle::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::Node* const&)+0xac
              libswiftCore.dylib`swift_getTypeByMangledNodeImpl(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x179
              libswiftCore.dylib`swift::swift_getTypeByMangledNode(swift::Demangle::Demangler&, swift::Demangle::Node*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift_getTypeByMangledNameImpl(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x3f9
              libswiftCore.dylib`swift::swift_getTypeByMangledName(llvm::StringRef, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x1b6
              libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>)+0x36e
              libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const+0x21a
              libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptorRef<swift::InProcess>, swift::TargetWitnessTable<swift::InProcess> const**)+0x2a
            90000
==========
total malloc calls: 1440330
@weissi
Copy link
Member Author

@weissi weissi commented Mar 1, 2019

tried this on a few Swift 5 versions, same everywhere, most recent one I tested:

$ jw-swift-latest swift -version
Apple Swift version 5.0-dev (LLVM 3207a50965, Clang 107de882f4, Swift feacc3fd31)
Target: x86_64-apple-darwin18.5.0

@belkadan
Copy link
Contributor

@belkadan belkadan commented Mar 4, 2019

@eeckstein
Copy link
Member

@eeckstein eeckstein commented Mar 4, 2019

I'm already working on this. It's easily fixable

@eeckstein
Copy link
Member

@eeckstein eeckstein commented Mar 7, 2019

@weissi
Copy link
Member Author

@weissi weissi commented Mar 9, 2019

Thanks so much Erik! I’ll check out Monday’s snapshot build and report back .

@weissi
Copy link
Member Author

@weissi weissi commented Mar 11, 2019

I can verify this as fixed. SwiftNIO's test now do 600 fewer allocations per connection pair (http client and http server) with identical code. Thanks very much @eeckstein

after

$ SWIFT_EXEC=/Users/johannes/devel/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swiftc IntegrationTests/run-tests.sh -f tests_04
[...]
Running test suite 'tests_04_performance'
Running test 'test_01_allocation_counts_for_http1.sh'... warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_1000_reqs_1_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=30687
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_1_reqs_1000_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=717000
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=4555
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2009
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_future_lots_of_callbacks)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=99001
OK (69s)
OK (ran 1 tests successfully)

before

Running test suite 'tests_04_performance'
Running test 'test_01_allocation_counts_for_http1.sh'... warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_1000_reqs_1_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=48267
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_1_reqs_1000_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=1317909
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=10697
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=5012
warning: no reference number of allocations set (set to $MAX_ALLOCS_ALLOWED_future_lots_of_callbacks)
warning: to set current number:
warning:     export MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=99004
OK (55s)
OK (ran 1 tests successfully)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants