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

Excessive Memory Usage on Linux when Compiling Large Arrays #60549

Open
NeedleInAJayStack opened this issue Aug 14, 2022 · 2 comments
Open

Excessive Memory Usage on Linux when Compiling Large Arrays #60549

NeedleInAJayStack opened this issue Aug 14, 2022 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@NeedleInAJayStack
Copy link

NeedleInAJayStack commented Aug 14, 2022

Describe the bug
When compiling large array literals in a Linux environment, Swift uses an extremely large amount of memory. For example, memory usage exceeds 500MB when compiling a 1000 element array literal composed of simple structs. If the array is declared as an existential, memory usage balloons to 2GB.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Clone this reproducer repo: https://github.com/NeedleInAJayStack/CompileMemUsageReproducer
  2. Follow the workflow in the readme

Watching the memory usage via docker stats is definitely not ideal, but I'm not familiar with a better approach to extract peak memory usage or diagnostics from the Swift compiler. I'm definitely open to suggestions here. When collecting the observed peak usage numbers, the swift build command was run multiple times in a row and the maximum number observed in docker stats was recorded.

Expected behavior
Large array literals are able to be compiled with a much smaller amount of memory than currently observed. At runtime these arrays are significantly less than 1MB, yet take many times that amount to compile.

Environment (please fill out the following information)

  • OS: Ubuntu 20.04
  • Swift: Nightly toolchain (August 10 at time of filing)
  • Xcode Version/Tag/Branch: N/A

Additional context
This may be related to #58380

@NeedleInAJayStack NeedleInAJayStack added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Aug 14, 2022
@Austinpayne
Copy link

cc: @asl

@asl
Copy link
Contributor

asl commented Oct 18, 2022

The issue could be reproduced on MacOS as well. Besides the memory consumption, the running time also depends on # of elements. Here is the profiler trace for LargeExistentialArray.swift:
Screenshot 2022-10-18 at 17 11 47

LargeObjectArray.swift has the peak memory consumption / time also in constraint solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants