Skip to content

Read all DWARF abbreviations tables in a single pass#15515

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:perf/debug-abbrev
Feb 26, 2025
Merged

Read all DWARF abbreviations tables in a single pass#15515
straight-shoota merged 1 commit intocrystal-lang:masterfrom
HertzDevil:perf/debug-abbrev

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Feb 25, 2025

This avoids the need to reseek the executable IO for every single DWARF unit header, which can considerably speed up the debug info loader for large binaries, such as the Crystal compiler itself. The following are the mean run times for load_debug_info_impl sampled by running a locally built x86_64-linux-gnu Crystal compiler 100 times each, forcing the load on program startup with CRYSTAL_LOAD_DEBUG_INFO=1:

  • Non-release, before: 553 ± 4.1 ms
  • Non-release, after: 428 ± 3.3 ms (29% faster)
  • Release, before: 144 ± 4.6 ms
  • Release, after: 142 ± 6.1 ms

There are no significant improvements on x86_64-windows-gnu. I'm unsure why. It however does wonders on WSL2 Debian when the executable is on a Windows filesystem:

  • Before, compiler: 11800 ms
  • After, compiler: 564 ± 35 ms
  • Before, empty file: 3220 ms
  • After, empty file: 92.8 ± 17 ms

For the record, the times are printed using:

struct Exception::CallStack
  def self.load_debug_info : Nil
    return if ENV["CRYSTAL_LOAD_DEBUG_INFO"]? == "0"

    unless @@dwarf_loaded
      @@dwarf_loaded = true
      begin
        t1 = Time.monotonic
        load_debug_info_impl
        t2 = Time.monotonic
        STDERR.puts (t2 - t1).total_milliseconds
      rescue ex
        @@dwarf_line_numbers = nil
        @@dwarf_function_names = nil
        Crystal::System.print_exception "Unable to load dwarf information", ex
      end
    end
  end
end

Release builds are largely unaffected because their abbreviations tables are extremely small, even with --debug passed.

@straight-shoota straight-shoota added this to the 1.16.0 milestone Feb 25, 2025
@straight-shoota straight-shoota merged commit e088dd5 into crystal-lang:master Feb 26, 2025
35 checks passed
@HertzDevil HertzDevil deleted the perf/debug-abbrev branch February 28, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants