Skip to content

Slow builds for larger resources embedded in code #75288

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

Open
nixberg opened this issue Sep 18, 2023 · 8 comments
Open

Slow builds for larger resources embedded in code #75288

nixberg opened this issue Sep 18, 2023 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. type checker Area → compiler: Semantic analysis

Comments

@nixberg
Copy link

nixberg commented Sep 18, 2023

Description

As suggested in the PR, Resource.embedInCode(_:) appears to be inefficient for larger resources.
For a minimal .executableTarget with a 165 KB resource to be embedded, the debug build takes some 200 seconds on my machine. 19 seconds for the release build.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

No response

@nixberg nixberg added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Sep 18, 2023
@neonichu
Copy link
Contributor

I hadn't even thought about compilation speed tbh. I wonder whether #68141 makes this better since we essentially generate a large array.

@nixberg
Copy link
Author

nixberg commented Sep 19, 2023

FWIW. Somewhat subquadratic in debug mode, roughly linear in release mode.

Debug:
 25K:   7.15s
 50K:  21.65s
100K:  77.35s
200K: 300.21s

Release:
 25K:   3.33s
 50K:   5.86s
100K:  11.31s
200K:  23.20s

@Lancelotbronner
Copy link

I had a 1.2 MB JSON file (https://lua-api.factorio.com/latest/prototype-api.json), please note that embedInCode is unusable for this.

@migueldeicaza
Copy link

I had a 9 megabyte file, the compiler aborts due to the type check taking too long.

The generated file is a 30 megabyte swift file.

@MaxDesiatov MaxDesiatov transferred this issue from swiftlang/swift-package-manager Jul 17, 2024
@MaxDesiatov
Copy link
Contributor

If type checking is taking too long, I don't think there's anything specific to the package manager here. Moving the issue accordingly.

@MaxDesiatov MaxDesiatov added the type checker Area → compiler: Semantic analysis label Jul 17, 2024
@Lancelotbronner
Copy link

Lancelotbronner commented Jul 17, 2024

I read somewhere that clang implemented the C #embed using a special builtin.

Could Swift also do the same thing? Turning a 9 MB resource into a 30 MB generated file that then needs to be parsed and type-checked doesn't seem ideal.

@migueldeicaza
Copy link

Rather than introduce a new language extension, the compiler could just flag during parsing "I have seen that all of these are byte constants" as an annotation, and proceed without the type resolver.

@DagAgren
Copy link

DagAgren commented Nov 5, 2024

Is there any progress on this? I keep trying to use this feature only to find out it's basically unusable. I really want to use this!

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. type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

6 participants