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

Reduce memory footprint of the Swift compiler #14

Closed

Conversation

swiftix
Copy link
Contributor

@swiftix swiftix commented Nov 30, 2015

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.

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
@swiftix
Copy link
Contributor Author

swiftix commented Nov 30, 2015

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.

@XBeg9
Copy link

XBeg9 commented Dec 3, 2015

Set your branch title into WIP

@daydayfree
Copy link

👍

@yurikoles
Copy link

But there is no branch named 'trunk' in this repo ¯_(ツ)_/¯.

@codestergit
Copy link
Contributor

@swiftix 👍 You are hero. @yurikoles May be they use SVN internally. Am I right @swiftix

@swiftix swiftix force-pushed the recycle-sil-instructions-memory branch from bafb0e9 to 0768c76 Compare December 9, 2015 19:13
@swiftix
Copy link
Contributor Author

swiftix commented Dec 9, 2015

@codestergit We used to use SVN internally. These days we switched to git, but we sometimes still use trunk and master interchangeably.

@swiftix swiftix force-pushed the recycle-sil-instructions-memory branch from 0768c76 to 5c64804 Compare December 9, 2015 19:33
@nadavrot
Copy link
Contributor

nadavrot commented Dec 9, 2015

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.

@swiftix
Copy link
Contributor Author

swiftix commented Dec 9, 2015

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.

@swiftix swiftix force-pushed the recycle-sil-instructions-memory branch from 5c64804 to 46b58ac Compare December 10, 2015 16:52
@swiftix
Copy link
Contributor Author

swiftix commented Dec 10, 2015

Since this PR does not get automatically updated with changes from my branch, I'll submit a new one.

@swiftix swiftix closed this Dec 10, 2015
airspeedswift added a commit to airspeedswift/swift that referenced this pull request Oct 26, 2016
airspeedswift added a commit that referenced this pull request Oct 27, 2016
[stdlib] Make various free functions mutating an _ArrayBufferProtocol into extensions. Resolves ABI FIXME #14
slavapestov pushed a commit to slavapestov/swift that referenced this pull request Nov 27, 2018
…ake3

Propagate linker flags for kqueue and pthread_workqueue
slavapestov pushed a commit to slavapestov/swift that referenced this pull request Nov 27, 2018
…ake3

Propagate linker flags for kqueue and pthread_workqueue

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
kateinoigakukun referenced this pull request in kateinoigakukun/swift Nov 15, 2019
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
lorentey pushed a commit that referenced this pull request Dec 11, 2019
kateinoigakukun referenced this pull request in kateinoigakukun/swift Dec 14, 2019
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
kateinoigakukun referenced this pull request in kateinoigakukun/swift Jan 11, 2020
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
kateinoigakukun referenced this pull request in kateinoigakukun/swift Jan 24, 2020
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
MaxDesiatov referenced this pull request in MaxDesiatov/swift May 1, 2020
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
DougGregor pushed a commit to DougGregor/swift that referenced this pull request Apr 28, 2024
Windows: add ICU packaging rules
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Jun 26, 2024
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.
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Jun 26, 2024
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.
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Jun 26, 2024
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.
nate-chandler added a commit to nate-chandler/swift that referenced this pull request Jun 26, 2024
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.
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.

6 participants