Skip to content

Conversation

@jpellegrini
Copy link
Contributor

The most interesting is APPEND. It really becomes faster, and conses much less.

(import (scheme list))

(let ((a (iota 10000))
      (b (map - (iota 10000))))
  (time (repeat 10000 (append a b))))

Old code:
4097.964 ms
100000000 allocation calls

New code:
2899.566 ms
10000 allocation calls

Plus, the code doesn't use goto anymore, AND we report different errors for cyclic lists, improper lists and no-lists. :)

STk_argv2list is only used twice in object.c, but still... It now
conses much less.
Sligitly faster, conses much less:

```
(import (scheme list))

(define-macro (L i)
  `(list ,@(iota i)))

(time (repeat 10000 (apply list (L 1000))))
```

740.866 ms
20000000 allocation calls

613.931 ms
10010000 allocation calls
Big improvement by using STk_C_make_list:

```
(import (scheme list))

(let ((a (iota 10000))
      (b (map - (iota 10000))))
  (time (repeat 10000 (append a b))))
```

Old code:
4097.964 ms
100000000 allocation calls

New code:
2899.566 ms
10000 allocation calls

Plus, the code doesn;'t use goto anymore, AND we report different
errors for cyclic lists, improper lists and no-lists. :)
```
(import (scheme vector @))

(let ((a (make-u64vector 5000 5)))
  (time (begin (repeat 10000 (%uvector->list a 7)) #t)))
```

Old code:
2492.513 ms
50000000 allocation calls

New code:
1937.452 ms
10000 allocation calls

But (scheme vector @) seems to not yet use this (it has Scheme code
for turning the vectors into lists, we should be using %uvector->list
instead...)
Using STk_C_make_list
@jpellegrini
Copy link
Contributor Author

jpellegrini commented Apr 15, 2025

A quick grep on STk_cons shows that there are relevant places where STk_C_make_list could also be used:

lib/stklos/itrie.c
lib/srfi/170.c
lib/srfi/238.c
lib/srfi/178.c
lib/scheme/sort.c
lib/scheme/vector/base.c
lib/scheme/list.c

(Not counting single uses of STk_cons, only those that seem to be called repeatedly in order to build a list.)

@egallesio
Copy link
Owner

For some reason, the code of STk_append2 in this PR fails when booting. The code seems correct, but. I have not (yet) understood why it fails (debugging is not simple since it happens very soon).

Anyway, I have done some tests on the other patches, and as I said in #769, the gain of STk_C_make_list is less important now. I will look in further detail at all the (other) patches to see the one we can keep.

@jpellegrini
Copy link
Contributor Author

Hmmm. The nice thing about that is this part:

the code doesn;'t use goto anymore, AND we report different errors for cyclic lists, improper lists and no-lists

I'll see if we can implement the different-lists error reporting directly with the new code

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

Successfully merging this pull request may close these issues.

2 participants