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

Slow list creation #42

Open
mvpeterson opened this issue Mar 21, 2024 · 8 comments
Open

Slow list creation #42

mvpeterson opened this issue Mar 21, 2024 · 8 comments

Comments

@mvpeterson
Copy link

mvpeterson commented Mar 21, 2024

It takes about 1 minute to create a list of 24 elements in minimal Metta.
Is there a way to make it work faster?

(= (makelist $x)
(if (== () $x) Nil (let $_cdr (cdr-atom $x)
                                (Cons (car-atom $x) (makelist $_cdr)))
                   )
)

!(makelist (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24))
[(Cons 1 (Cons 2 (Cons 3 (Cons 4 (Cons 5 (Cons 6 (Cons 7 (Cons 8 (Cons 9 (Cons 10 (Cons 11 (Cons 12 (Cons 13 (Cons 14 (Cons 15 (Cons 16 (Cons 17 (Cons 18 (Cons 19 (Cons 20 (Cons 21 (Cons 22 (Cons 23 (Cons 24 Nil))))))))))))))))))))))))]

@noskill
Copy link
Contributor

noskill commented Mar 22, 2024

adding types doesn't change the performance

(: List (-> $t Type))
(: Nil (List $t))
(: Cons (-> $t (List $t) (List $t)))

; convert (a b c) to (Cons a (Cons b (Cons c Nil)))
(: makelist (-> Atom (List $t)))

@vsbogd
Copy link
Contributor

vsbogd commented Mar 22, 2024

Interesting that Python is six times slower than Rust REPL on this task which is strange.

@ngeiswei
Copy link
Collaborator

This issue somewhat relates to one I've just created as well trueagi-io/hyperon-experimental#638

@vsbogd
Copy link
Contributor

vsbogd commented Mar 22, 2024

From the code logic perspective nothing is wrong here. Although I recommend adding types as @noskill suggested in #42 (comment).

It is a performance issue. So I would suggest closing it as a duplicate of trueagi-io/hyperon-experimental#638

@noskill
Copy link
Contributor

noskill commented Mar 22, 2024

@vsbogd is the issue caused by argument of car-atom being evaluated? If so why it gets evaluated? I remember you told me that built-in metta types are not evaluated

@vsbogd
Copy link
Contributor

vsbogd commented Mar 22, 2024

@vsbogd is the issue caused by argument of car-atom being evaluated?

It is not evaluated in this context. If you see it is evaluated in log the reason is == has type (-> $t $t Bool).

@noskill
Copy link
Contributor

noskill commented Mar 26, 2024

What do you think about adding differently typed == operator?

@noskill
Copy link
Contributor

noskill commented Mar 26, 2024

works faster, but not much

(: same (-> Atom Atom Bool))

(= (same $X $Y) False)
(= (same $X $X) True)

(= (makelist $x)
    (if (same () $x) Nil (let $_cdr (cdr-atom $x)
                                (Cons (car-atom $x) (makelist $_cdr)))
                   )
)

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

4 participants