Skip to content

Enhancement: Improve tracing performance#989

Merged
hhubert6 merged 5 commits into
mainfrom
975-improve-tracing-performance-switch-to-erlang-trace
May 15, 2026
Merged

Enhancement: Improve tracing performance#989
hhubert6 merged 5 commits into
mainfrom
975-improve-tracing-performance-switch-to-erlang-trace

Conversation

@hhubert6
Copy link
Copy Markdown
Contributor

@hhubert6 hhubert6 commented May 12, 2026

I've tried several approaches to improve performance, but none of them yielded a significant enough impact to comfortably handle the MemoryExplosion examples included in the dev app.

Some of the things I tried that give noticeable difference:

  • Using file port in :dbg.tracer with :dbg.trace_client
    • :follow_file creates challenges of manual file size management (I haven't gone deeper on that)
    • :file with FileWrapSpec manages file size well but does not support streaming traces live so it becomes really problematic with iterative traces fetching
  • Using ip port in :dbg.tracer with :dbg.trace_client
  • Replacing :dbg.tracer with plain :erlang.trace
  • Using custom erl_tracer NIF for reducing trace size by dropping some field like socket from assigns in render/1 callback or assigns from socket in other callback (e.g. handle_event/3)
  • Dynamic spawning of TraceHandler GenServer for load balancing of incoming traces

All listed options give somewhat noticeable difference in performance and/or memory usage but each potentially creates known challenges or ones that may occur later. That's why I went with simple replacement of :dbg.tracer with :erlang.trace as it's least prone to unknown issues, the easiest to manage and gives visible increase in performance.

Based on what I've researched, attempting to improve performance beyond that would require fundamental and extensive redesign of the entire tracing logic, likely involving different design assumptions than those we initially made.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the tracing layer to reduce runtime overhead by replacing :dbg usage with direct :erlang.trace/3 and :erlang.trace_pattern/3 calls, and updates callback tracer docs/tests accordingly.

Changes:

  • Replace :dbg-backed tracer with a dedicated registered tracer process and direct BEAM tracing BIFs (LiveDebugger.API.System.Dbg).
  • Adjust tracing flag usage to reduce global tracing overhead and enable per-LiveView process tracing where needed.
  • Update documentation/comments and test expectations to match the new tracing behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/services/callback_tracer/gen_servers/tracing_manager_test.exs Updates mock expectations for new per-process tracing flags.
test/services/callback_tracer/actions/tracing_test.exs Updates mock expectations for revised Dbg.process/1,2 flag lists.
lib/live_debugger/structs/trace.ex Clarifies trace id documentation.
lib/live_debugger/services/callback_tracer/README.md Updates tracer architecture documentation away from :dbg.tracer.
lib/live_debugger/services/callback_tracer/process/tracer.ex Updates docs/comments to reflect the new tracer handler model.
lib/live_debugger/services/callback_tracer/gen_servers/tracing_manager.ex Broadens :DOWN handling to match any tracer termination reason.
lib/live_debugger/services/callback_tracer/gen_servers/trace_handler.ex Updates comments to reference the new Dbg-started tracer process.
lib/live_debugger/services/callback_tracer/actions/tracing.ex Adjusts global and per-process tracing flag configuration for performance.
lib/live_debugger/api/system/dbg.ex Core refactor: implements tracing via :erlang.trace/3 and :erlang.trace_pattern/3 with a custom tracer process.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/live_debugger/api/system/dbg.ex Outdated
Comment thread lib/live_debugger/api/system/dbg.ex
Comment thread lib/live_debugger/services/callback_tracer/gen_servers/tracing_manager.ex Outdated
Comment thread lib/live_debugger/api/system/dbg.ex Outdated
@hhubert6 hhubert6 force-pushed the 975-improve-tracing-performance-switch-to-erlang-trace branch from b274691 to 17f1010 Compare May 12, 2026 12:45
@hhubert6 hhubert6 marked this pull request as ready for review May 12, 2026 12:51
Copy link
Copy Markdown
Member

@kraleppa kraleppa left a comment

Choose a reason for hiding this comment

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

Very nice!

Comment thread lib/live_debugger/services/callback_tracer/actions/tracing.ex Outdated
@hhubert6 hhubert6 requested a review from kraleppa May 14, 2026 10:48
Copy link
Copy Markdown
Member

@kraleppa kraleppa left a comment

Choose a reason for hiding this comment

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

nice 🐬

Copy link
Copy Markdown
Contributor

@GuzekAlan GuzekAlan left a comment

Choose a reason for hiding this comment

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

LGTM 🦈

@hhubert6 hhubert6 merged commit bde824e into main May 15, 2026
5 of 6 checks passed
@hhubert6 hhubert6 deleted the 975-improve-tracing-performance-switch-to-erlang-trace branch May 15, 2026 10:03
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.

4 participants