Lukas Tenbrink
d2f9d31270
Make more types (`Callable`, `Signal`) conversion to `String` explicit.
2025-06-10 23:55:35 +02:00
dementive
d2814ebbf3
Add missing Color hash function
2025-06-08 14:49:50 -04:00
Rémi Verschelde
61639d9574
Merge pull request #106996 from Ivorforce/no-oa-hashmap
...
Core: Remove `OAHashMap`, in favour of `AHashMap`
2025-06-05 13:12:34 +02:00
aaronp64
6b2674fe18
Reuse and optimize sorting logic for List, SelfList, and HashMap
...
Added SortList class, and updated List, SelfList, and HashMap sort methods to use it. Sorting is done with merge sort, with an initial check to optimize for already sorted lists, and sorted lists that were appended to.
2025-06-04 10:18:22 -04:00
Thaddeus Crews
7a3d2f6779
Merge pull request #106606 from aaronfranke/pow2_64
...
Add 64-bit versions of core power of 2 functions
2025-06-02 18:51:56 -05:00
Aaron Franke
f6f1df7d73
Add 64-bit versions of core power of 2 functions
2025-06-01 23:11:12 -07:00
Lukas Tenbrink
c3476b8205
Fix `FixedVector` move semantics.
2025-05-31 18:22:16 +02:00
Lukas Tenbrink
963c20565b
Remove `OAHashMap`, in favour of `AHashMap`.
...
The two types had (mostly) the same decisions, but `AHashMap` is a faster implementation, and is more consistent with `HashMap`.
2025-05-31 15:50:10 +02:00
LuoZhihao
21e2bac382
Add missing headers in FixedVector and Span
2025-05-30 13:41:45 +08:00
Thaddeus Crews
2cde9292c3
Merge pull request #106876 from Ivorforce/localvector-no-force-trivial
...
Un-support `force_trivial` parameter for `LocalVector`. Instead, users should use `resize_uninitialized`.
2025-05-28 09:47:45 -05:00
Lukas Tenbrink
37415530d7
Un-support `force_trivial` parameter for `LocalVector`. Instead, users are reformatted to use `resize_uninitialized` to make it explicit that the resize does not initialize missing elements.
2025-05-27 18:43:36 +02:00
Lukas Tenbrink
d2d57849de
Add a safety check for `CowData::_unref()`, for when something tries to add elements during destruction.
2025-05-27 18:00:48 +02:00
Thaddeus Crews
0c12e758ac
Merge pull request #106569 from Ivorforce/hashmap-if-mod
...
Accelerate `HashMap` and `HashSet` lookup by using `if` based modulo in loops
2025-05-27 09:39:29 -05:00
Lukas Tenbrink
670ab7a383
Add `resize_initialized` and `resize_uninitialized` to `LocalVector`.
2025-05-26 18:35:41 +02:00
Lukas Tenbrink
4cb8a0c77e
Add `resize_initialized` and `resize_uninitialized` to `Vector`. These functions serve as replacements for `resize`, to make sure the caller understands whether elements need to be initialized 'by hand' after the call.
2025-05-26 18:35:41 +02:00
Lukas Tenbrink
4371aa864d
Simplify `Memory::memnew_arr_placement` to always initialize memory, to force callers to make the decision of whether to initialize.
2025-05-22 22:25:12 +02:00
Thaddeus Crews
15cd5e1619
Merge pull request #106689 from aaronp64/ringbuffer_localvector
...
Use `LocalVector` for `RingBuffer`
2025-05-22 12:15:03 -05:00
Thaddeus Crews
c3c3657a0d
Merge pull request #106661 from KirbyRider1337/dont-compare-the-same-item-with-itself
...
Prevent comparison of items with themselves while partitioning sort arrays
2025-05-22 12:14:58 -05:00
KirbyRider1337
caf8053b86
Adjusted get_median_from_3 and partitioner to also retrieve the pivot's index and check if either end of the partitioner has reached it to avoid comparing things with themselves
2025-05-21 14:38:09 -04:00
aaronp64
2a02cabe4d
Use LocalVector for RingBuffer
...
Updated RingBuffer to use LocalVector instead of Vector, to avoid _copy_on_write overhead when writing to the buffer.
2025-05-21 13:50:10 -04:00
Lukas Tenbrink
70f8dd29f5
Simplify use of `LocalVector` `force_trivial` template parameter.
2025-05-19 20:27:14 +02:00
Thaddeus Crews
2d42b889d1
Merge pull request #104124 from Ivorforce/alloc-static-calloc
...
Add `Memory::alloc_static_zeroed` to allocate memory that's filled with zeroes.
2025-05-19 08:01:33 -05:00
Lukas Tenbrink
6fe17b264e
Use `if` based mod in `HashMap` and `HashSet` in loops (faster than `fastmod`).
2025-05-18 20:05:34 +02:00
Thaddeus Crews
5538850d87
Core: Convert `Pair`/`KeyValue` to `constexpr`
2025-05-15 10:37:41 -05:00
Yufeng Ying
3bf400ffae
Move bisect to Span and deduplicate code.
...
Co-authored-by: Lukas Tenbrink <lukas.tenbrink@gmail.com>
2025-05-14 18:19:09 +08:00
Yufeng Ying
0babb2ab02
Optimize HashMap size for zero-sized Allocators.
2025-05-13 21:44:39 +08:00
Lukas Tenbrink
3207066e19
Add `Memory::alloc_static_zeroed` to allocate memory that's filled with zeroes.
...
This is generally faster than `malloc` followed by `memset` / loop-set to 0.
2025-05-13 01:57:05 +02:00
Rémi Verschelde
4c62c8aceb
Merge pull request #106020 from Ivorforce/hashmap-duplicate-hash
...
Optimize `HashMap` insertion by removing duplicate computation of hash and position
2025-05-13 01:04:57 +02:00
Rémi Verschelde
2b037e8989
Merge pull request #93276 from mashumafi/avoid-vec-copy
...
Avoid unnecessary copy-on-write Vector/Array
2025-05-13 01:04:16 +02:00
mashumafi
b73346ef19
Avoid copy-on-write when reading vectors
2025-05-12 16:08:05 +02:00
Yufeng Ying
2db0a44519
Remove vmap.h
2025-05-09 19:05:28 +08:00
Lukas Tenbrink
1d49a557b6
Optimize away duplicate hash and position computation in `HashMap` on insert.
...
Co-authored-by: Nazarii <nazarii.yablonskyi.pp.2022@lpnu.ua>
2025-05-02 19:02:03 +02:00
Thaddeus Crews
01fc9aee6c
Core: Modernize C headers with C++ equivalents
2025-05-02 08:23:01 -05:00
Lukas Tenbrink
1b1ab76a14
Add `FixedVector` template.
...
This is a high performance `Vector`-like object that can be used if the maximum number of objects is small and known, and the objects are needed only temporarily.
2025-04-30 19:14:08 +02:00
Thaddeus Crews
44d20b2dc6
Merge pull request #100619 from Ivorforce/cowdata-resize-direct
...
Optimize / refactor `CowData`, combining resize and fork to avoid unnecessary reallocations.
2025-04-28 18:45:54 -05:00
lawnjelly
ae04a3a5dd
Physics Interpolation - Move 3D FTI to `SceneTree`
...
Moves 3D interpolation from server to the client code (`SceneTree`).
Complete rework of 3D physics interpolation, but using the same user API.
2025-04-26 14:13:30 +01:00
Lukas Tenbrink
d74ef8cb01
Rename `LocalVector.invert()` -> `LocalVector.reverse()` to match the `Vector`, `String` and `List` APIs.
2025-04-24 22:36:32 +02:00
Lukas Tenbrink
7c37188ca1
Smoke test: In collections, log an error if `reserve()` is called with a number smaller than the current size. Don't log an error if it is called with a number smaller than the current capacity.
2025-04-23 16:47:47 +02:00
Thaddeus Crews
2ffd5a3913
Merge pull request #104738 from YYF233333/cleanup_rid_owner
...
Use `LocalVector` in `RID_Owner::get_owned_list`
2025-04-22 10:44:25 -05:00
Thaddeus Crews
c0e695d5e8
Merge pull request #100944 from Nazarwadim/LocalVector_use_1.5x_growth_factor
...
Use 1.5x growth factor for LocalVector
2025-04-21 08:24:22 -05:00
Yyf2333
1a70a06a43
Change RID_Owner::get_owned_list.
2025-04-21 01:04:27 +08:00
clayjohn
c6c06a966a
Allow chunk validator to wrap around in RID_Alloc so that we do not need to crash once we have made 2^31 allocations
2025-04-18 00:06:53 -07:00
Lukas Tenbrink
015a3b0434
Optimize / refactor `CowData`, combining `resize` and `fork` to avoid unnecessary reallocations.
2025-04-15 17:01:26 +02:00
Thaddeus Crews
addab4f001
Merge pull request #95916 from Repiteo/core/bit-field
...
Core: Add dedicated `BitField` template
2025-04-11 13:29:13 -05:00
Thaddeus Crews
0d267e7b1e
Core: Add dedicated `BitField` template
2025-04-11 11:53:26 -05:00
Lukas Tenbrink
b711d72e8f
Remove unnecessary `friend class` declarations of `CowData`.
...
Use default implementations for various containers.
2025-04-11 18:26:08 +02:00
Thaddeus Crews
94282d88f9
Core: Use `Math` namespace for constants
2025-04-10 16:29:30 -05:00
Thaddeus Crews
5edb235018
CI: Bump various pre-commit hooks
2025-04-07 08:23:35 -05:00
Thaddeus Crews
207a2b6472
Core: Integrate warning suppression macro helpers
2025-04-03 10:13:46 -05:00
Lukas Tenbrink
ccdc5862e9
Add `LocalVector.erase_unordered`, mimicking `erase` but with `remove_at_unordered`, to remove duplicate logic.
...
`erase_unordered` should be preferred over `erase` where order is not important, for its performance benefits.
Co-authored-by: smix8 <smix8@users.noreply.github.com>
2025-03-31 13:31:53 +02:00
Rémi Verschelde
afc7398c2b
Merge pull request #104616 from ibrahn/init-cmd-q-pending-and-gles3-skymatdata
...
Fix uninitialized member vars in CommandQueueMT and RasterizerSceneGLES3
2025-03-28 17:30:37 +01:00
Rémi Verschelde
4a31936bc1
Merge pull request #104693 from mihe/local-vector-move
...
Optimize `LocalVector::push_back` for non-trivial objects
2025-03-28 14:34:49 +01:00
Rémi Verschelde
76c30189fa
Merge pull request #103923 from Ivorforce/span-array-init
...
Add C array constructor to `Span`.
2025-03-28 14:32:14 +01:00
Mikael Hermansson
5c5b9847da
Optimize `LocalVector::push_back` for non-trivial objects
2025-03-27 14:22:30 +01:00
Ibrahn Sahir
c9352f06f7
Fix uninitialised member vars in CommandQueueMT and RasterizerSceneGLES3
2025-03-25 17:19:16 +00:00
Thaddeus Crews
8f16b86d7e
Core: Include `intrin.h` for MSVC
2025-03-24 15:19:49 -05:00
Thaddeus Crews
4c9086312d
Merge pull request #103698 from AThousandShips/fix_a_hash_map_construct
...
[Core] Fix `AHashMap` constructors reserving too few elements
2025-03-23 19:03:59 -05:00
Thaddeus Crews
f09ee0171a
Style: Begin integrating simple `.clangd` fixes
2025-03-22 13:24:35 -05:00
Rémi Verschelde
64bd03269f
Merge pull request #104286 from Ivorforce/localvector-find
...
Harmonize `String`, `Vector` and `LocalVector` `find` and `rfind`.
2025-03-19 12:27:27 +01:00
Lukas Tenbrink
fde71e0382
Harmonize `String`, `Vector` and `LocalVector` `find` and `rfind`.
...
Use `Span::find` for `LocalVector::find`, accepting negative `p_from`.
Return `-1` for invalid `p_from` values in `rfind`.
Accept negative values for `p_from` in `find`, starting from the back.
2025-03-18 12:37:36 +01:00
Thaddeus Crews
4320800621
Core: Expand `is_zero_constructible` coverage
2025-03-17 11:45:26 -05:00
Lukas Tenbrink
49e860159a
Move `CowData` `find`, `rfind` and `count` to `Span`.
2025-03-16 03:31:11 +01:00
Lukas Tenbrink
78221946cc
Add C array constructor to `Span`. [skip ci]
2025-03-12 16:48:16 +01:00
Thaddeus Crews
74907876d3
Merge pull request #103759 from Ivorforce/zero-constructible
...
Optimize `Array.resize` by using `memset` (through new `is_zero_constructible` type trait)
2025-03-12 10:31:55 -05:00
Lukas Tenbrink
75bc471965
Add `is_zero_constructible` to denote if a type can be semi-trivially constructed with all 0 bytes.
...
Optimize `CowData` and `LocalVector` resize for zero constructible types.
Mark several compatible types as `is_zero_constructible`.
2025-03-12 09:49:24 +01:00
Lukas Tenbrink
55a7de93c7
Add iteration to `Span`.
2025-03-11 23:46:25 +01:00
Lukas Tenbrink
f5cb739a18
Add `Span` conversion to `LocalVector`.
2025-03-10 22:30:39 +01:00
Thaddeus Crews
a13067e61f
Merge pull request #97553 from AThousandShips/semantic_equal
...
[Core] Add `is_same` to types that have float components
2025-03-10 10:01:05 -05:00
Lukas Tenbrink
605b62cd29
Add `Span` struct (replacing `StrRange`). Spans represent read-only access to a contiguous array, resembling `std::span`.
2025-03-09 18:19:51 +01:00
Thaddeus Crews
324512e11c
Style: Replace header guards with `#pragma once`
2025-03-07 17:33:47 -06:00
A Thousand Ships
fad8134dca
[Core] Fix `AHashMap` constructors reserving too few elements
2025-03-06 15:28:37 +01:00
Pāvels Nadtočajevs
bdb5d522d1
Use atomic flag to prevent `flush_if_pending` from reading unlocked `command_mem`.
2025-02-25 23:26:43 +02:00
A Thousand Ships
e825085978
[Core] Add `is_same` to types that have float components
...
Compares `NaN` as equal.
Added to:
* `AABB`
* `Basis`
* `Color`
* `Plane`
* `Projection`
* `Quaternion`
* `Rect2`
* `Transform2D`
* `Transform3D`
* `Vector2`
* `Vector3`
* `Vector4`
And added as a method in `Math`
2025-02-03 19:25:50 +01:00
Matias N. Goldberg
7b2f1e1d09
Fix union order to simplify empty initializers
...
This is a followup to PR #101344 (commit
0e06eb80bc ).
Some of them were not an issue because Godot was initializing all
members, but they were "fixed" just in case since it could become a
problem in the future.
Valgrind was specifically complaining about HashMapData &
GlobalPipelineData.
2025-01-14 19:05:01 -03:00
Lukas Tenbrink
cf145de21e
Revert regression (GH-31736) of memory unsafe append_array (append vector to itself). Add comments to prevent future regressions.
2025-01-10 15:30:36 +01:00
Nazarii
6609caf76e
Use 1.5x growth factor for LocalVector
2025-01-10 15:57:54 +02:00
Aarni Koskela
f134769506
Fix various typos
...
* Add TODO notes for typos that should be fixed for 5.0
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
2025-01-08 14:47:42 +02:00
Rémi Verschelde
1aaf20b1f1
Merge pull request #98488 from RandomShaper/lockless_rid_fetch_pro
...
Fix `RID_Owner` synchronization
2025-01-06 08:38:14 +01:00
Pedro J. Estébanez
de7e4efef8
Fix RID_Owner synchronization
2025-01-03 17:05:36 +01:00
Rémi Verschelde
21e6671740
Merge pull request #100937 from Repiteo/style/clang-format-sync
...
Style: Enforce `AllowShortFunctionsOnASingleLine`
2025-01-03 00:49:44 +01:00
Rémi Verschelde
dd7d36e803
Merge pull request #100770 from hpvb/command-queue-mt
...
Core: Refactor CommandQueueMT to use vararg templates for performance and maintainability
2025-01-03 00:49:02 +01:00
Thaddeus Crews
e06d83860d
Style: Enforce `AllowShortFunctionsOnASingleLine`
2025-01-02 10:09:41 -06:00
HP van Braam
cccd2432c3
Refactor CommandQueueMT to use vararg templates
...
In order to make CommandQueueMT more maintainable this PR changes the
previous macro hell with variadic templates instead. This makes the
class far more explicit and will allow us to more easily change the way
the class functions in the future.
Furthermore this refactoring has allowed for some optimizations. In
particular by using std::forward to delay the decision of decaying the
type to as late as possible we are able to move the data from the
callsite into our Command buffer and later move it to the call.
In practice what this means is that compared to the old version instead
of copying values 3 times, we can now get away with 1 copy, and 1 move
for lvalues, and just 2 moves for rvalues. This saves quite a few
operations in a hot codepath.
We also now test to make sure that the amount of copies and moves are
what we expect. This way we can spot performance regressions in this
code easily.
Somewhat unscientifically, running TPS-demo by pressing enter and not
touching the controls average mspf, repeatable across many runs:
before: 6.467
after : 6.202
2025-01-02 15:35:08 +01:00
Thaddeus Crews
08d4dd7fd8
Merge pull request #100694 from Ivorforce/cowdata-destruct-graciously
...
Destruct `CowData` more graciously by avoiding accidentally exposing a half-destructed buffer.
2024-12-23 11:15:18 -06:00
Lukas Tenbrink
25cd923ea1
Destruct `CowData` more graciously by avoiding accidentally exposing a half-destructed buffer. This can avoid problems if any of the destructed objects tries to access the data while it's being destructed.
2024-12-21 20:01:03 +01:00
Lukas Tenbrink
0e32f3b957
Make `LocalVector` -> `Vector` automatic conversion safe for non-trivial types.
2024-12-21 10:28:57 +01:00
Thaddeus Crews
151e7fc687
Merge pull request #100477 from Ivorforce/cowdata-move-insert-n-remove
...
Optimize `CowData` and `LocalVector` functions `.insert` and `.remove_at` by using move semantics.
2024-12-19 20:00:20 -06:00
Thaddeus Crews
1b8a2d930f
Merge pull request #100474 from Ivorforce/cowdata-abstract-realloc
...
Abstract `CowData`'s reallocations into `_realloc` to consolidate duplicate logic.
2024-12-19 20:00:19 -06:00
Thaddeus Crews
bf9ef5f8a5
Merge pull request #100564 from YYF233333/iwyu
...
Remove unused headers in core
2024-12-19 19:59:55 -06:00
Thaddeus Crews
92615f24e7
Merge pull request #100563 from Ivorforce/move-semantics-list
...
Add move semantics (constructor, operator=) to `List`.
2024-12-19 19:59:54 -06:00
Thaddeus Crews
0b01f3cc14
Merge pull request #100560 from Ivorforce/localvector-move-semantics
...
Add `LocalVector` move semantics (constructor and operator=).
2024-12-19 19:59:51 -06:00
Lukas Tenbrink
8483d794ff
Abstract `CowData`'s reallocations into `_realloc` to consolidate duplicate logic.
2024-12-19 17:27:16 +01:00
Lukas Tenbrink
3564e7c231
Add `LocalVector` move semantics (constructor and operator=).
2024-12-19 15:05:05 +01:00
Lukas Tenbrink
19992e3284
Add move semantics (constructor, operator=) to `List`.
2024-12-19 15:04:15 +01:00
Thaddeus Crews
361e3b4fe8
Core: Expand `std::initializer_list` support
2024-12-18 18:46:59 -06:00
Yufeng Ying
be86ce3103
Apply iwyu suggestion in core.
2024-12-19 00:43:47 +08:00
HP van Braam
240f510fa7
Core ubsan fixes
...
This fixes UBSAN errors reported by running our testsuite, importing the
TPS demo, and running the TPS demo. I have tried, wherever possible, to
fix issues related to reported issues but not directly reported by UBSAN
because thse code paths just happened to not have been exercised in
these cases.
These fixes apply only to errors reported, and caused by, core/
The following things have been changed:
* Make sure there are no implicit sign changing casts in core.
* Explicitly type enums that are part of a public API such that users of
the API cannot pass in wrongly-sized values leading to potential stack
corruption.
* Ensure that memcpy is never called with invalid or null pointers as
this is undefined behavior, and when the engine is built with
optimizations turned on leads to memory corruption and hard to debug
crashes.
* Replace enum values only used as static values with constexpr static
const values instead. This has no runtime overhead. This makes it so
that the size of the enums is explicit.
* Make sure that nan and inf is handled consistently in String.
* Implement a _to_int template to ensure that all of the paths use the
same algorhithm, and correct the negative integer case.
* Changed the way the json serializer precision work, and added tests to
verify the new behavior. The behavior doesn't quite match master in
particulary for negative doubles as the original code tried to cast -inf
to an int. This then led to negative doubles losing all but one of
their decimal points when serializing. Behavior in GDScript remains
unchanged.
2024-12-18 14:31:12 +01:00
Lukas Tenbrink
a636c04244
Optimize `CowData` and `LocalVector` functions `.insert` and `.remove_at` by using move semantics.
2024-12-17 14:10:10 +01:00
Lukas Tenbrink
57073ba14e
Add move constructor and move assignment to CowData, String, Char16String, CharString and Vector.
2024-12-11 15:52:15 +01:00
Sai Nane
66b7d5f1b5
Remove apparent contradiction in vector.h header
...
3205a92ad8 was a major commit which removed `PoolVector`, and replaced
most references to `PoolVector` with `Vector` instead. In most cases,
this was appropriate, given that `PoolVector` was being replaced with
`Vector`, as an effective generalist in 64-bit address space layouts.
However, vector.h itself was left with an artifact advising the reader
to use `Vector` instead of `Vector` for large arrays. While this led
to a fascinating deep dive, and hopefully improved some of the
documentation along the way, it's probably best to clean this up for
the next person.
2024-12-10 01:51:30 +00:00