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

Superlinear compile time for large arrays of constants #52868

Closed
RalfJung opened this issue Jul 30, 2018 · 4 comments
Closed

Superlinear compile time for large arrays of constants #52868

RalfJung opened this issue Jul 30, 2018 · 4 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Jul 30, 2018

pub static FIELDS: [&i32; BIG_NUMBER] =[
    &("bar", 42, "foo", 3.14).1,
   ...
];

takes superlinear time to compile as BIG_NUMBER increases:

6 * 1024: 4s
12 * 1024: 20s
24 * 1024: 131s

Built using CARGO_INCREMENTAL=0 cargo build --release on current nightly.

Looks at least quadratic to me.

Cc @oli-obk

Python script to generate code
#!/usr/bin/python3
import sys

SIZE = int(sys.argv[1]) * 1024

def print_array_elems(elem):
    sys.stdout.write("[\n")
    for i in range(SIZE):
        sys.stdout.write("    "+elem+",\n")
    sys.stdout.write("]")

def print_array(name, elem_type, elem):
    sys.stdout.write("pub static {}: [{}; {}] =".format(name, elem_type, SIZE))
    print_array_elems(elem)
    sys.stdout.write(";\n")

print_array("FIELDS", "&i32", '&("bar", 42, "foo", 3.14).1')
@nagisa
Copy link
Member

nagisa commented Jul 30, 2018

This, I believe, is a duplicate of… (takes a look through I-compiletime)… let’s say #37155.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 6, 2018

FWIW, the quadratic complexity occurs already with nightly-2018-07-07, i.e., before the CTFE loop checker landed.

EDIT: In fact, even nightly-2017-10-01 has the problem already. That's before miri was put into rustc. So I think @nagisa you are right, this is probably an ancient issue.

@nagisa
Copy link
Member

nagisa commented Aug 6, 2018

Lets close this in order to not clutter the issue list then.

@nagisa nagisa closed this as completed Aug 6, 2018
@nagisa
Copy link
Member

nagisa commented Aug 6, 2018

Since I’m pretty sure this is a duplicate of one of those I-compiletime issues. I encourage to post your test case on one of those.

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

No branches or pull requests

2 participants