Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

WIP: Pure Attribute/Widget definitions #54

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

TimLariviere
Copy link
Owner

@TimLariviere TimLariviere commented Jan 24, 2022

Removed the auto-incremented key and the need for AttributeDefinitionStore and WidgetDefinitionStore.
Now their keys are their names, so all definitions require a unique name.

Attributes and widgets now take a direct reference to their definitions.

I had to change a lot of stuff to avoid having everything interdependent (type ... and ... and ... and ...).
But I feel most of my changes make even more sense than before. So I'm quite happy.

Only ViewNode is currently very loosely defined. I have to properly think this one.

For now only the project Fabulous compiles

@TimLariviere
Copy link
Owner Author

TimLariviere commented Jan 24, 2022

@twop I had to use the name of AttributeDefinition for the sorting key. You can't do GetHashCode on a record holding functions.

{ ScalarAttributes =
match StackList.length &scalarAttributes with
| 0us -> ValueNone
| _ -> ValueSome(Array.sortInPlace (fun a -> a.Definition.Key) (StackList.toArray &scalarAttributes))
Copy link
Collaborator

Choose a reason for hiding this comment

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

That is what I was referring when I mentioned that we need a fast comparison key, unfortunately a.Definition.Key is a potential double cache miss. And string is heap allocated value itself, thus comparing it will involve another memory jump.

So the way I was thinking about it is to use string as a user facing Key: requite unique string for each widget and for each attribute (exactly as you do it currently here). But with a twist:

  1. When you create a definition calculate a hash of that string and store it in the attribute and addition to the reference to the definition. {Key = "AttrKey"; Hash = 14565; ...}
  2. in DEBUG mode have a global table lookup to ensure uniqueness (both for string and hash)

Then we have direct access to Definition but also have a key for fast sorting (int)

I was planning to use that hash prop to store additional attributes in a couple of bits.

Value: ArraySlice<Widget> }

/// Represents a virtual UI element such as a Label, a Button, etc.
and [<Struct>] WidgetData =
{ ScalarAttributes: ScalarAttribute[] voption
Copy link
Collaborator

Choose a reason for hiding this comment

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

also it is possible that we might want to optimize voption in here in the future. Maybe with direct null checks.
voption adds 4 bytes overhead :( Or maybe build ourselves TinyOption that is based on bool with custom pattern matching

@TimLariviere
Copy link
Owner Author

I'm putting this one on hold. Not completely satisfied with what I did

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants