-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Reduce memory footprint of the Swift compiler #14
Conversation
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler. For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured. The use-after-free issues reported by build bots are fixed now. rdar://23303031
DON'T MERGE IT INTO TRUNK YET! We are going to test on build bots for a couple of days or for a week and if everything is fine, we'll merge it afterwards. |
Set your branch title into |
👍 |
But there is no branch named 'trunk' in this repo ¯_(ツ)_/¯. |
@swiftix 👍 You are hero. @yurikoles May be they use SVN internally. Am I right @swiftix |
bafb0e9
to
0768c76
Compare
@codestergit We used to use SVN internally. These days we switched to git, but we sometimes still use trunk and master interchangeably. |
0768c76
to
5c64804
Compare
I think it would be great if anyone would be willing to help us test this pull request. For example, you can build it on Linux and use valgrind to catch bugs, etc. |
Yes, I agree with @nadavrot. But please use the most up-to-date version from the swiftix:recycle-il-instructions-memory branch. GitHub does not update it properly here. |
5c64804
to
46b58ac
Compare
Since this PR does not get automatically updated with changes from my branch, I'll submit a new one. |
[stdlib] Make various free functions mutating an _ArrayBufferProtocol into extensions. Resolves ABI FIXME #14
…ake3 Propagate linker flags for kqueue and pthread_workqueue
…ake3 Propagate linker flags for kqueue and pthread_workqueue Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
New WASI SDK package should contain a new version of the linker. Also, the script should now create an installable package on macOS so that one could create a full SwiftWasm package later after the build. * Update WASI SDK, create installable package on macOS * Fix sysroot path, update wasi-sdk on Linux * Exclude module net for wasm SDK in glibc.modulemap * Remove module termios from glic.modulemap for wasm * Disable _stdlib_mkstemps for wasm
New WASI SDK package should contain a new version of the linker. Also, the script should now create an installable package on macOS so that one could create a full SwiftWasm package later after the build. * Update WASI SDK, create installable package on macOS * Fix sysroot path, update wasi-sdk on Linux * Exclude module net for wasm SDK in glibc.modulemap * Remove module termios from glic.modulemap for wasm * Disable _stdlib_mkstemps for wasm
New WASI SDK package should contain a new version of the linker. Also, the script should now create an installable package on macOS so that one could create a full SwiftWasm package later after the build. * Update WASI SDK, create installable package on macOS * Fix sysroot path, update wasi-sdk on Linux * Exclude module net for wasm SDK in glibc.modulemap * Remove module termios from glic.modulemap for wasm * Disable _stdlib_mkstemps for wasm
New WASI SDK package should contain a new version of the linker. Also, the script should now create an installable package on macOS so that one could create a full SwiftWasm package later after the build. * Update WASI SDK, create installable package on macOS * Fix sysroot path, update wasi-sdk on Linux * Exclude module net for wasm SDK in glibc.modulemap * Remove module termios from glic.modulemap for wasm * Disable _stdlib_mkstemps for wasm
New WASI SDK package should contain a new version of the linker. Also, the script should now create an installable package on macOS so that one could create a full SwiftWasm package later after the build. * Update WASI SDK, create installable package on macOS * Fix sysroot path, update wasi-sdk on Linux * Exclude module net for wasm SDK in glibc.modulemap * Remove module termios from glic.modulemap for wasm * Disable _stdlib_mkstemps for wasm
Windows: add ICU packaging rules
Apply the same control-flow changes to the method that were applied on main to avoid duplicated implementations one of which crashes with ``` Metadata for archetype not bound in function. The metadata could be missing entirely because it needs to be passed to the function. Or the metadata is present and not bound in which case setScopedLocalTypeMetadata or similar must be called. Archetype without metadata: Value (primary_archetype_type address=0x14207ebe0 conforms_to="Swift.(file).Escapable" name="Value" (interface_type=generic_type_param_type depth=0 index=0 decl="Synchronization.(file)._Cell.Value@/Volumes/ams1_ext4/Submit/SWE/DevTools/swift/6_0_0_6/swift/stdlib/public/Synchronization/Cell.swift:19:23")) Function: ; Function Attrs: noinline nounwind define linkonce_odr hidden ptr @"$s15Synchronization5_CellVyxGRi_zlWOb"(ptr %0, ptr %1, ptr %2) swiftlang#14 !dbg !8 { %4 = alloca i1, align 1 } LocalTypeData: (0x14207f5f8 (_Cell<Value>), FormalTypeMetadata) => [ (universal) concrete: 0x600003d1add0 ptr %2 ] ``` when building Synchronization.
Apply the same control-flow changes to the method that were applied on main to avoid duplicated implementations one of which crashes with ``` Metadata for archetype not bound in function. The metadata could be missing entirely because it needs to be passed to the function. Or the metadata is present and not bound in which case setScopedLocalTypeMetadata or similar must be called. Archetype without metadata: Value (primary_archetype_type address=0x14207ebe0 conforms_to="Swift.(file).Escapable" name="Value" (interface_type=generic_type_param_type depth=0 index=0 decl="Synchronization.(file)._Cell.Value@/Volumes/ams1_ext4/Submit/SWE/DevTools/swift/6_0_0_6/swift/stdlib/public/Synchronization/Cell.swift:19:23")) Function: ; Function Attrs: noinline nounwind define linkonce_odr hidden ptr @"$s15Synchronization5_CellVyxGRi_zlWOb"(ptr %0, ptr %1, ptr %2) swiftlang#14 !dbg !8 { %4 = alloca i1, align 1 } LocalTypeData: (0x14207f5f8 (_Cell<Value>), FormalTypeMetadata) => [ (universal) concrete: 0x600003d1add0 ptr %2 ] ``` when building Synchronization.
Apply the same control-flow changes to the method that were applied on main to avoid duplicated implementations one of which crashes with ``` Metadata for archetype not bound in function. The metadata could be missing entirely because it needs to be passed to the function. Or the metadata is present and not bound in which case setScopedLocalTypeMetadata or similar must be called. Archetype without metadata: Value (primary_archetype_type address=0x14207ebe0 conforms_to="Swift.(file).Escapable" name="Value" (interface_type=generic_type_param_type depth=0 index=0 decl="Synchronization.(file)._Cell.Value@/Volumes/ams1_ext4/Submit/SWE/DevTools/swift/6_0_0_6/swift/stdlib/public/Synchronization/Cell.swift:19:23")) Function: ; Function Attrs: noinline nounwind define linkonce_odr hidden ptr @"$s15Synchronization5_CellVyxGRi_zlWOb"(ptr %0, ptr %1, ptr %2) swiftlang#14 !dbg !8 { %4 = alloca i1, align 1 } LocalTypeData: (0x14207f5f8 (_Cell<Value>), FormalTypeMetadata) => [ (universal) concrete: 0x600003d1add0 ptr %2 ] ``` when building Synchronization.
Apply the same control-flow changes to the method that were applied on main to avoid duplicated implementations one of which crashes with ``` Metadata for archetype not bound in function. The metadata could be missing entirely because it needs to be passed to the function. Or the metadata is present and not bound in which case setScopedLocalTypeMetadata or similar must be called. Archetype without metadata: Value (primary_archetype_type address=0x14207ebe0 conforms_to="Swift.(file).Escapable" name="Value" (interface_type=generic_type_param_type depth=0 index=0 decl="Synchronization.(file)._Cell.Value@/path/to/swift/6_0_0_6/swift/stdlib/public/Synchronization/Cell.swift:19:23")) Function: ; Function Attrs: noinline nounwind define linkonce_odr hidden ptr @"$s15Synchronization5_CellVyxGRi_zlWOb"(ptr %0, ptr %1, ptr %2) swiftlang#14 !dbg !8 { %4 = alloca i1, align 1 } LocalTypeData: (0x14207f5f8 (_Cell<Value>), FormalTypeMetadata) => [ (universal) concrete: 0x600003d1add0 ptr %2 ] ``` when building Synchronization.
This is a cleaned-up version of my previous patch to use malloc/free instead of BumpPtrAllocator for SILInstructions. It fixed a few remaining errors reported by build bots.
Since this feature can eventually destabilise the compiler if there are some not yet detected errors, let's test is more thoroughly on our build bots for a while before we merge it into trunk.