Skip to content

base: growable_array#6411

Draft
michaellilltokiwa wants to merge 2 commits intotokiwa-software:mainfrom
michaellilltokiwa:expanding_array2
Draft

base: growable_array#6411
michaellilltokiwa wants to merge 2 commits intotokiwa-software:mainfrom
michaellilltokiwa:expanding_array2

Conversation

@michaellilltokiwa
Copy link
Copy Markdown
Member

@michaellilltokiwa michaellilltokiwa commented Dec 15, 2025

old:

/home/not_synced/flang_dev/fzweb (main)130$ /home/sam/openvscode-server-fuzion/vscode-fuzion/fuzion/build/bin/fz  -jvm -JLibraries="wolfssl sodium" -modules=http,lock_free,uuid,mail,wolfssl,crypto,sodium,nom,web -sourceDirs=src,benchmarks benchmarks
session_document.get_content tutorial iter/s: 13.0
session_document.get_content news iter/s: 13.9
session_document.get_content . iter/s: 112.4
Session.event_msg tutorial iter/s: 13.8
Session.event_msg news iter/s: 13.9
Session.event_msg . iter/s: 98.5

new:

/home/not_synced/flang_dev/fzweb (main)$ /home/sam/openvscode-server-fuzion/vscode-fuzion/fuzion/build/bin/fz  -jvm -JLibraries="wolfssl sodium" -modules=http,lock_free,uuid,mail,wolfssl,crypto,sodium,nom,web -sourceDirs=src,benchmarks benchmarks
session_document.get_content tutorial iter/s: 15.8
session_document.get_content news iter/s: 16.4
session_document.get_content . iter/s: 149.0
Session.event_msg tutorial iter/s: 16.4
Session.event_msg news iter/s: 15.7
Session.event_msg . iter/s: 129.0

This is likely mostly due to String.concat being faster.

old:
    /home/not_synced/flang_dev/fzweb (main)130$ /home/sam/openvscode-server-fuzion/vscode-fuzion/fuzion/build/bin/fz  -jvm -JLibraries="wolfssl sodium" -modules=http,lock_free,uuid,mail,wolfssl,crypto,sodium,nom,web -sourceDirs=src,benchmarks benchmarks
    session_document.get_content tutorial iter/s: 13.0
    session_document.get_content news iter/s: 13.9
    session_document.get_content . iter/s: 112.4
    Session.event_msg tutorial iter/s: 13.8
    Session.event_msg news iter/s: 13.9
    Session.event_msg . iter/s: 98.5

new:
    /home/not_synced/flang_dev/fzweb (main)$ /home/sam/openvscode-server-fuzion/vscode-fuzion/fuzion/build/bin/fz  -jvm -JLibraries="wolfssl sodium" -modules=http,lock_free,uuid,mail,wolfssl,crypto,sodium,nom,web -sourceDirs=src,benchmarks benchmarks
    session_document.get_content tutorial iter/s: 15.8
    session_document.get_content news iter/s: 16.4
    session_document.get_content . iter/s: 149.0
    Session.event_msg tutorial iter/s: 16.4
    Session.event_msg news iter/s: 15.7
    Session.event_msg . iter/s: 129.0
@michaellilltokiwa michaellilltokiwa changed the title expanding_array2 base: growable_array Dec 16, 2025
@michaellilltokiwa
Copy link
Copy Markdown
Member Author

@tokiwa-software/developers Looking for feedback on this:

Difference to expanding_array:

  • does not (and probably can not easily) support fancy stuff like the expand feature expand(n i32, filler ()->unit) expanding_array T
  • the datalayout: is an internal_array T instead of internal_array (slot T), which means there is no need for copying when creating an array from it.
  • thread safe (At least I think it is)
  • Instead of indirection on every entry, one indirection with the reference to the Store.

@michaellilltokiwa michaellilltokiwa requested a review from a team January 27, 2026 17:19
else if c2 = 0
Sequence.this
else if c1 < 0 || c2 < 0 || max 1 c1 < c2 then
else if c1 < 0 || c2 < 0 then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably want to revert this, as discussed in the office there was a reason for this.

Comment on lines +40 to +55
# growable_array -- an array with a length and a (possible larger) capacity
#
# An expanding array is a persistent data structure that has cumulative O(1)
# performance of adding single elements at its end.
#
# WARNING: Due to the high worst-case time for addition, this structure should
# not be used in situations when adding a single element repeatedly to the same
# instance of `growable_array`. If the resulting
# `growable_array`'s length is `l`, this will trigger the worst-case
# addition time, resulting in cumulative time O(m*l) for adding an element m
# times.
#
# This constructor is for internal use only, to create instance of
# `growable_array`, use `(growable_array T).type.empty` to create an empty
# expanding array instance.
#
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just the same comment copied from expanding_array. what is different?

Comment on lines +85 to +98
# create a new `growable_array` with element i set to v. Grow the array
# in case i == length.
#
# expand is not thread-safe.
#
# Complexity: O(1) if no allocation is required, O(length+1) otherwise.
#
# Cumulative complexity of adding an element to an empty `growable_array`
# and repeatedly growing the result `add` by a total of `n` elements is
# `O(n)`.
#
# `add` called repeatedly on the same `growable_array` creates copies
# of the underlying array data and hence has performance in `O(length)`.
#
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, copied comment?

Comment on lines +134 to +136
# create an expanding_array that consists of all the elements of this Sequence followed
# by all the elements of s
#
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it creates a growable_array, not an expanding_array?

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