Commit graph

477 commits

Author SHA1 Message Date
Olivier Goffart
dff19c52da Fix assertion failed: lhs_lookup.is_local_to_component
Fixes #6632
2024-10-28 11:44:25 +01:00
Milian Wolff
89bc023819 Optimize: Filter/map rowan nodes instead of doing multiple lookups
Instead of doing potentially multiple calls in the chained calls,
each of which would allocate in rowan, we now only call the iterator
function once and then leverage `find_map`. This is arguably even
more readable and it removes ~300k allocations and speeds up parsing.

Before:
```
  Time (mean ± σ):     930.7 ms ±  15.1 ms    [User: 678.7 ms, System: 165.5 ms]
  Range (min … max):   906.4 ms … 956.3 ms    10 runs

    allocations: 2339130

```

After:
```
  Time (mean ± σ):     914.6 ms ±  22.7 ms    [User: 649.6 ms, System: 174.5 ms]
  Range (min … max):   874.8 ms … 946.3 ms    10 runs

    allocations: 2017915

```
2024-10-28 09:40:58 +01:00
Milian Wolff
79e1592b9f Intern some more common types
This is just for completeness, we "only" save ~13k allocations
with no measurable speed impact:

Before:
```
  Time (mean ± σ):      1.019 s ±  0.033 s    [User: 0.716 s, System: 0.203 s]
  Range (min … max):    0.957 s …  1.061 s    10 runs

        allocations:            2679001

```

After:
```
  Time (mean ± σ):      1.015 s ±  0.015 s    [User: 0.715 s, System: 0.201 s]
  Range (min … max):    0.997 s …  1.038 s    10 runs

        allocations:            2666889
```
2024-10-28 09:39:54 +01:00
Milian Wolff
6e9e66ea7d Refactor typeregister's BUILTIN_ENUMS => BUILTIN.enums
This will allow us to add more buildin types to this thread local
in follow-up patches, to reduce the number of thread local slots.
2024-10-28 09:39:54 +01:00
Milian Wolff
0abfb056a1 Also use Rc for langtype::Type::Array
This is rarely used, but using Rc here like elsewhere allows us to
elide a few unneccessary memory allocations when copying such types.
The speed impact is not measurable though. With heaptrack I see that
we get rid of the last ~7600 allocations in my benchmark when cloning
Type.
2024-10-28 09:39:54 +01:00
Milian Wolff
69c68b22b2 Also wrap langtype::Type::Struct in an Rc
This makes copying such types much cheaper and will allow us to
intern common struct types in the future too. This further
drops the sample cost for langtype.rs from ~6.6% down to 4.0%.

We are now also able to share/intern common struct types.

Before:
```
  Time (mean ± σ):      1.073 s ±  0.021 s    [User: 0.759 s, System: 0.215 s]
  Range (min … max):    1.034 s …  1.105 s    10 runs

        allocations:            3074261
```

After:
```
  Time (mean ± σ):      1.034 s ±  0.026 s    [User: 0.733 s, System: 0.201 s]
  Range (min … max):    1.000 s …  1.078 s    10 runs

        allocations:            2917476
```
2024-10-28 09:39:54 +01:00
Milian Wolff
efdecf0a13 Wrap langtype::Type::{Callback,Function} data in an Rc
This allows us to cheaply copy the langtype::Type values which
contain such a type. The runtime impact is small and barely noticable
but a sampling profiler shows a clear reduction in samples pointing
at langtype.rs, roughly reducing that from ~8.6% inclusive cost
down to 6.6% inclusive cost.

Furthermore, this allows us to share/intern common types.

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):      1.089 s ±  0.026 s    [User: 0.771 s, System: 0.216 s]
  Range (min … max):    1.046 s …  1.130 s    10 runs

        allocations:            3152149
```

After:
```
  Time (mean ± σ):      1.073 s ±  0.021 s    [User: 0.759 s, System: 0.215 s]
  Range (min … max):    1.034 s …  1.105 s    10 runs

        allocations:            3074261
```
2024-10-28 09:39:54 +01:00
Olivier Goffart
716b31e6c8 Use PopupClosePolicy enum from the type register instead of re-creating it 2024-10-24 13:11:11 +02:00
FloVanGH
14c7910d49
PopupWindow: added close-policy property (#6614)
* Update api/cpp/include/slint_window.h

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update docs/reference/src/language/builtins/elements.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update internal/core/window.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/interpreter/eval.rs

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update internal/backends/qt/qt_window.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/interpreter/dynamic_item_tree.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/compiler/passes/materialize_fake_properties.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-10-24 09:27:39 +00:00
Olivier Goffart
9e2576bc5c swrenderer: Small fixup in distance field
- include the ' ' char that doesn't have a bounding box but need to be
   included for the advance_x
 - Fix an off by one in rendering where the last pixel was missing
2024-10-24 08:12:13 +02:00
Simon Hausmann
094a8ea718 Add missing par_iter() call
Amends 08c3f7a79a
2024-10-23 19:42:35 +02:00
Simon Hausmann
08c3f7a79a Fix order of glyphs in BitmapFont's glyphs when using SDFs
Initially the character map is ordered by glyph index. Maintain that order for glyph embedding, so that we can safely collect() the bitmaps. Just before creating the final BitmapFont data structure, sort by code point for fast lookups at run-time.
2024-10-23 19:36:51 +02:00
Simon Hausmann
0ebcbbecbe Speed up SDF generation
Using Rayon shaves off ~10% off of gallery.slint on my M3.
2024-10-23 09:12:30 +02:00
Olivier Goffart
d8ab4e4600 Signed DistanceField font rendering in swrenderer
Note that this is still disabled in the compiler with no way to enable
it with public API
2024-10-23 09:12:30 +02:00
Simon Hausmann
0e404c835c Fix warnings about unused fields in glyph embedding
Make them always used by centralizing the design metrics reading code.
2024-10-23 09:12:30 +02:00
Simon Hausmann
241eb35a2d Fix compiler warning about unused function 2024-10-23 09:12:30 +02:00
Simon Hausmann
557729320f Blind attempt at fixing the sdf sizes
Scale the bounding box to the desired target pixel size and use the full range of the bitmap we have for the distances.
2024-10-23 09:12:30 +02:00
Simon Hausmann
a1231f1826 Fix panic when emojis appear in the font
For now, generate empyt bitmap glyphs instead of causing a panic.
2024-10-23 09:12:30 +02:00
Simon Hausmann
7b94b58a63 Don't generate glyph bitmaps for characters not present in any font 2024-10-23 09:12:30 +02:00
Simon Hausmann
18f645f814 WIP: Being adding support for generating SDF glyphs 2024-10-23 09:12:30 +02:00
Olivier Goffart
4e50fbdb15 Fix panic making an alias to a private property
Fixes #6587
2024-10-22 09:35:31 +02:00
Tobias Hunger
7f8da7bf28 compiler: Do not fail the embed_images pass with URLs
Slintpad uses URLs to images. Do not fail when we "embed"
those so that we find the list of resources on the Documents
later.

This fixes image loading in slintpad again.
2024-10-21 15:00:55 +02:00
Milian Wolff
d3905b4c41 Use to_smolstr in a few more places to reduce allocation pressure
Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     626.1 ms ±  16.0 ms    [User: 548.6 ms, System: 72.6 ms]
  Range (min … max):   610.9 ms … 653.0 ms    10 runs

        allocations:            3395727
        temporary allocations:  466634
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     622.6 ms ±  13.9 ms    [User: 556.6 ms, System: 63.5 ms]
  Range (min … max):   609.7 ms … 645.4 ms    10 runs

        allocations:            3371931
        temporary allocations:  459315
```
2024-10-17 18:04:58 +02:00
Milian Wolff
0f6c3a4fd7 Use SmolStr in more places of the compiler infrastructure
This removes a lot of allocations and speeds up the compiler step
a bit. Sadly, this patch is very invasive as it touches a lot of
files. That said, each individual hunk is pretty trivial.

For a non-trivial real-world example, the impact is significant,
we get rid of ~29% of all allocations and improve the runtime by
about 4.8% (measured until the viewer loop would start).

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     664.2 ms ±   6.7 ms    [User: 589.2 ms, System: 74.0 ms]
  Range (min … max):   659.0 ms … 682.4 ms    10 runs

        allocations:            4886888
        temporary allocations:  857508
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     639.5 ms ±  17.8 ms    [User: 556.9 ms, System: 76.2 ms]
  Range (min … max):   621.4 ms … 666.5 ms    10 runs

        allocations:            3544318
        temporary allocations:  495685
```
2024-10-17 18:04:58 +02:00
Olivier Goffart
13d44130d9
Fix compiler panic binding to property with syntax error (#6572)
Fixes #6519
2024-10-16 21:35:35 +02:00
Olivier Goffart
f0e02a3aa3 Fix panic with invalid code
Fix #6518
2024-10-15 11:42:28 +02:00
Tobias Hunger
e55f2ae04e compiler: Add a ListResources option for resource embedding
... which will list all resources that are not going to get embedded
as `None` in the Document's `embedded_file_reosurces`.

The idea is to use that field to find all used resources in the
live preview so that we know what we can watch.
2024-10-14 11:31:34 +02:00
Simon Hausmann
0b028bfb6f
Add support for a font-metrics property to Text/TextInput. (#6452)
The struct held provides access to the design metrics of the font scaled
to the font pixel size used by the element.

ChangeLog: Slint Language: Added font-metrics property to `Text` and `TextInput`.

Closes #6047
2024-10-05 17:00:46 +02:00
Olivier Goffart
d6706494a5
Binding between a read only property to input-output is deprecated (#6419)
ChangeLog: deprecated two way binding between `in` and `in-out` property

Fixes #6400
2024-10-01 16:00:06 +02:00
FloVanGH
fd9807515f
TextInput: use selection colors from palette (#6381)
* Update internal/compiler/builtins.slint

Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>

---------

Co-authored-by: Olivier Goffart <olivier.goffart@slint.dev>
2024-09-30 10:56:22 +00:00
Olivier Goffart
53e79000a4
Layouting: Take in account explicit constraints when generating layout info base on content (#6306)
Fixes #6285

ChangeLog: Fixed geometry constraints when they are partially infered
from the content, and partially infered from the explicit constraints
2024-09-30 10:57:23 +02:00
Florian Blasius
71d1d814ce Revert "TextInput: use selection colors from palette"
This reverts commit 044518ee81.
2024-09-30 08:43:41 +02:00
Florian Blasius
044518ee81 TextInput: use selection colors from palette 2024-09-30 08:41:41 +02:00
Olivier Goffart
61565e1ba9 Visit expressions of changed callback during binding analysis
Fixes #6331  (second part)
2024-09-26 17:54:21 +02:00
Olivier Goffart
87d72a8553 Fix changed callback of an unused property
If the property was not used, it was optimized out and the compiler
would panic
Fixes #6331

ChangeLog: compiler: Fix changed callback of an unused property
2024-09-26 16:51:31 +02:00
Enyium
4509496143
Improve layout-related error message. (#6264)
The phrasing shouldn't be universal, so users aren't taught it would always apply to *all* kinds of layouts.
2024-09-24 09:43:02 +02:00
Olivier Goffart
bcdc3e1cee Timer: make the interval property mandatory
A default of 0 is not a great default because that's way too often
2024-09-18 09:24:39 +02:00
Olivier Goffart
3b6cc0f8cf Flickable: size in % bow refer to the Flickable's size instead of the viewport
This is consistant so that `width: 100%` is the same as `width: parent.width`

This basically revert the previous commit that was just working around
the debug_assert to actually fix the behavior

ChangeLog: width and height expressed in `%` unit for an element in a
Flickable now refer to the size of the Flickable instead of that of
the viewport
2024-09-12 09:45:24 +02:00
Olivier Goffart
e98780fafc Fix compiler panic when using % size in a flickable
The viewport of a flickable is of ElementType::Native, and `lookup_property`
don't query the builtin reserved properties in that case.

This commit fix the assert by allowing Type::Invalid as well.

Fixes #4163
2024-09-12 09:45:24 +02:00
Olivier Goffart
0c8a9fcefb Fix compiler panic when accessing path.commands in expressions
Fixes #5564
2024-09-10 13:36:09 +02:00
Olivier Goffart
ea3072d696 Path: fix panic when accessing properties on sub commands
We need to keep the ElementRc around with its properties so that
accessing them doesn't panic later
2024-09-10 11:44:13 +02:00
Olivier Goffart
bf1b014840 Timer: fix timer when two timers have the same id
We need to give unique name to optimized item as well, otherwise the
properties ends up the same.

Also fix the optimized element and timer when inlining

Fixes #5977
Fixes #5976
2024-08-28 16:21:34 +02:00
Tobias Hunger
90e55bd29f compiler: Fix a couple of clippy issues
Nothing major, nothing controversial, just killing time
while waiting on CI.
2024-08-26 08:45:52 +02:00
Tobias Hunger
45c24803f2 compiler: Remove version info from SourceFile again
... and fix the fallout of that change.
2024-08-21 16:55:13 +02:00
Olivier Goffart
f7171e1fc1 Fixup children insertion point in the flickable
Last commit uncovered some bug in which the second phase of inlining
tries to inline children in the wrong place

(This usually inlines zero children as it was already done in the first
phase, but we still assert that the location is right)
2024-08-19 16:27:11 +02:00
Olivier Goffart
a69966a296 Fix @children is the root
We were not respting the order (index) at this point.

Fixes #5865
2024-08-19 16:27:11 +02:00
Olivier Goffart
a9f526491a Timer Element
Closes #5724
2024-08-16 16:36:38 +02:00
Olivier Goffart
2643a327e8 Change events: keep unused property with change event 2024-08-16 16:36:38 +02:00
Olivier Goffart
3a12ebf7ab Report an error when accessing a function within a PopupWindow
instead of panicking

Fixes #5852
2024-08-16 10:31:13 +02:00
Olivier Goffart
9b71cf1a36 Math postfix member functions on numbers
Closes #5328
2024-08-15 14:52:13 +02:00