Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic rewrite #378

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

Epic rewrite #378

wants to merge 6 commits into from

Conversation

nazmulidris
Copy link
Member

@nazmulidris nazmulidris commented Feb 3, 2025

Started with

  • [core][tui] Clean up emoji use in logs, enhance tracing support
  • [all] Promote scripting.rs from rust_scratch/tls

Also ended up doing

  • Rewrite entire codebase to use smallvec and smallstr
  • Change UnicodeString impl and UnicodeStringSegment
  • Fix edi bugs
  • Change units from ChUnit to strongly typed units for height, width, row, col, dim, and pos.
  • Implement new telemetry system using ringbuffer (no global static or use of atomics)

Issues closed

Create 2 new crates:
- script
- log
  - support UnicodeString for output
  - update all calls to tracing::*() to work seamlessly with CustomEventFormatter
    across the entire r3bl codebase (especially r3bl_tui examples)
  - add of the `options: impl Into<TracingConfig>` pattern for configuring the
    log functionality. this is ergonomic for simple cases (for the caller) and
    provides sophisticated configuration possibilities due to its composability.

Reorganize all the existing crates as well, to ensure that
known duplicated functions are removed.

Add new glyphs that are unicode character based, not emojis,
so that the fg, bg color and attributes are applied in output.
Emojis come with their own colors, so the fg and bg colors don't
get applied.

Use Vec::with_capacity wherever possible to prevent having reallocations
which are expensive, and create a global size limit for the all the r3bl
crates.
…ce tuning

- Data oriented design: https://youtu.be/WwkuAqObplU?si=5JPiDCfAG4YQxlhG
- Memory alloc: https://youtu.be/pJ-FRRB5E84?si=EGD_Tge1ApGRkT6n&t=1831
- Scalarize/flatten: https://youtu.be/Dhn-JgZaBWo?si=oFiWnwKEhfJFxZCL

Refactor ch_unit.rs:
- Remove `ch!` and replace it easier to understand functions that
  are easier to compose, and produce better compiler errors.

Change the memory usage of the codebase:
- Preallocate as much as possible.
- Allocate on the stack when possible.
- Reduce the size of fields if they don't need to store large `usize`
  values.

Update telemetry_global_static to provide MAX FPS

Implement RingBuffer and RateLimiter

Add support for `$TERM_PROGRAM` equals `vscode` to enable truecolor

Add TimeDuration struct to format Duration in a performant
and human readable way. No memory is allocated in the Display
trait implementation (the function that renders `{}`).

Update all Cargo.toml to Rust edition 2024

Remove `static_global_data.rs` module. Telemetry is now handled via the
`Telemetry` struct, and `RateLimiter` and `RingBuffer`.

Add rendering hints to Telemetry along with the telemetry_record!
macro to make the telemetry measurement ergonomic and self
documenting

Clean up log output to use tracing::debug!, etc. correctly
with message = {message}, etc.
[ At the start ... ]

This is the 2 week long refactor that is showing performance
regression over the previous commit!

excluding the following:
- tui/md_parser/convert_to_plain_text.rs
- tui/syntax_highlighting/intermediate_types.rs
- tui/syntax_highlighting/md_parser_syn_hi/md_parser_syn_hi_impl.rs

The files in this commit had to be rolled back as part of the changes
made in the last commit were breaking all the tui tests, especially
around MD parsing. These files still need the memory optimization work:
- stack vs heap app
- use write! instead of format!

[ And then ... ]

This commit brings the performance back up to previous commit with
SHA: 5603296

The slow down, as far as I can tell, from running different
commits side by side, is that the computation of the UnicodeString
proved to be quite expensive to do every time. So it is beneficial
to memoize this! Running the code with flamegraph profiling didn't
really show anything useful related to this problem.

Apply heap allocation techniques to the code in the following modules
to boost performance and keep it stable (steady):
- [x] formatter.rs
- [x] editor_engine.rs
- [x] convert_to_plain_text.rs
- [x] intermediate_types.rs
- [x] md_parser_syn_hi_impl.rs
Remove the complexity of having an editor_engine_internal_api.rs apply_changes()
function that accepts a closure by using a Drop impl on the struct returned by
editor_buffer_struct.rs get_mut().

Also fix this bug:
#343

Closes #343
@nazmulidris nazmulidris force-pushed the epic-rewrite branch 5 times, most recently from e091ab3 to 8372ca9 Compare February 3, 2025 15:26
Caret position can be of two kinds:
- Raw
- Scroll adjusted

Make this explicity using the type system and provide conversions
between the two.

Introduce new concrete types for:
- Pos
  - row
  - col
- Dim
  - width
  - height
- Use them in the codebase instead of ChUnit.
- Use ChUnit as the "inner" type of these new concrete types.
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.

[tui][edi] Loss of caret focus bugs [tui][edi] Clean up telemetry collection and reporting
1 participant