Optimize list comprehensions and sequence operator #386

Open
opened 2022-06-07 21:37:54 +09:00 by zxq9 · 2 comments
zxq9 commented 2022-06-07 21:37:54 +09:00 (Migrated from gitlab.com)

Created by: radrow

At this moment, list comprehensions and the .. operator compile to calls to an implicitly imported ListInternal namespace. Most importantly, LC performs numerous calls to flat_map which is not very performant. Instead of that, the compiler should produce code optimizing the number of passes through lists. Especially:

  • [f(x) | x <- l] could be a map
  • [x | x <- l, if p(x)] could be a filter
  • [f(x) | x <- l, p(x)] could be a single-pass combination of map and filter

And so on. We should consider if using inline assembly or functions would work better -- this might be determined by a flag, as there is a clear trade-of here.

*Created by: radrow* At this moment, list comprehensions and the `..` operator compile to calls to an implicitly imported `ListInternal` namespace. Most importantly, LC performs numerous calls to `flat_map` which is not very performant. Instead of that, the compiler should produce code optimizing the number of passes through lists. Especially: - `[f(x) | x <- l]` could be a `map` - `[x | x <- l, if p(x)]` could be a `filter` - `[f(x) | x <- l, p(x)]` could be a single-pass combination of `map` and `filter` And so on. We should consider if using inline assembly or functions would work better -- this might be determined by a flag, as there is a clear trade-of here.
zxq9 commented 2022-06-27 05:27:14 +09:00 (Migrated from gitlab.com)
*Created by: radrow* May be useful: https://www.researchgate.net/profile/Mario-Latendresse/publication/229001057_Simple_and_efficient_compilation_of_list_comprehension_in_Common_Lisp/links/09e4150a68b953e657000000/Simple-and-efficient-compilation-of-list-comprehension-in-Common-Lisp.pdf?origin=publication_detail
zxq9 commented 2022-06-27 05:34:03 +09:00 (Migrated from gitlab.com)

Created by: radrow

A loop construct in fcode could help

*Created by: radrow* A loop construct in fcode could help
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#386
No description provided.