Commit 86ae8977 authored by Doug Barrett's avatar Doug Barrett 🔴
Browse files

perf: reduce mutex contention with early checks

Add lock-free early checks before acquiring mutex in Registry methods.
Uses double-checked locking to reduce contention while maintaining
thread safety.

Relates-to: #60
parent 253354dd
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ module Labkit
        def record_offense(callsite, lineno, deprecated_field, standard_field, logger_class)
          key = [callsite, deprecated_field, logger_class].freeze

          return if @offense_keys.include?(key)

          @mutex.synchronize do
            next if @offense_keys.include?(key)

@@ -35,16 +37,15 @@ module Labkit
              'logger_class' => logger_class
            }.freeze

            # If this offense was previously marked as removed, undo that
            @removed_offenses.reject! { |r| offense_key(r) == key }
          end
        end

        def check_for_removed_offenses(callsite, fields, logger_class)
          @mutex.synchronize do
          baseline = baseline_by_callsite[[callsite, logger_class]]
            next unless baseline
          return unless baseline

          @mutex.synchronize do
            baseline.each do |offense|
              key = offense_key(offense)
              next if @offense_keys.include?(key)