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
[BUG] Excessive compilation time during manipulation of StaticTuple #2425
Comments
The issue here is that StaticTuple is defined as register passable despite having arbitrary size. This will never work well - register passable things should only be used for small types, not arbitrary size things like this. We need to get StaticTuple off of being register passable. |
StaticTuple will be removed soon once we replace uses with the InlineArray type that works on memory only types. Have you tried using that with a large size? |
@JoeLoser @lattner from utils import InlineArray
fn main():
var x = InlineArray[Int, 30_000](0)
for i in range(10):
# x[i] = i # Similair behavior
var ptr = x._get_reference_unsafe(i)
initialize_pointee_copy(UnsafePointer[Int](ptr), i) The compilation is also trivial when the index is known at compile time. the following compiles quite fast. var x = InlineArray[Int, 30_000](0)
for i in range(3):
x[50] = i |
hmm, the compilation time don't seem to be significantly different that I ran this on a quiet mdcm metal machine:
|
On my PC the initilization time of the array does not change much with the array size. Ex: the following code alias size = 30_000
var arr = InlineArray[Int, size](0)
print(arr[50]) time mojo build test.mojo
# size = 30_000
real 0m1.118s
# size = 30
real 0m0.335s However, the compilation of any addition ops on the array are size dependent. Ex: deref, emplace mutation. alias size = 31_000
var arr = InlineArray[Int, size](0)
for i in range(10):
print(arr.__refitem__(i)[])
print(arr[50]) time mojo build test.mojo
# size = 31_000
real 0m36.154s
# size = 30
real 0m0.361s |
Replace uses of `StaticTuple` with `InlineArray`. Soon, `StaticTuple` will be deprecated. This requires removing some reg-passable annotations on types since `StaticTuple` was register passable trivial, but `InlineArray` is of course not. As a bonus, this should speed up compile times a little bit since in some cases, we were using a `StaticTuple` of size `1024` which would not compile very fast. See #2425. MODULAR_ORIG_COMMIT_REV_ID: 004b5334e3bd78a8a8054d6762501efc557df716
Bug description
The following code takes around 40 seconds to compile with the actual execution time after build being trivial.
The compilation time is also tied to the Tuple size not the number of calling the
__setitem__()
function with Tuple size of 2_000 only lasting 3 secs.Steps to reproduce
System information
The text was updated successfully, but these errors were encountered: