Module: Rails::Hyperdrive::EagerFootprint
- Defined in:
- lib/rails/hyperdrive/eager_footprint.rb
Overview
Sizes the always-in-context set — the index-included guidelines — and returns the report as lines for a shell to print.
Defined Under Namespace
Classes: Line
Constant Summary collapse
- TOTAL_WARN_TOKENS =
Soft cap on the assembled eager set — roughly six at-the-limit guidelines, or ~5% of a 200k context window.
10_000
Class Method Summary collapse
Class Method Details
.approx_tokens(body) ⇒ Object
16 17 18 |
# File 'lib/rails/hyperdrive/eager_footprint.rb', line 16 def approx_tokens(body) (body.to_s.length / 4.0).ceil end |
.lines(guidelines:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails/hyperdrive/eager_footprint.rb', line 20 def lines(guidelines:) return [] if guidelines.empty? tokens = guidelines.sum { |e| approx_tokens(e[:body]) } result = [Line.new( status: :eager, message: "#{guidelines.size} guideline(s), ~#{tokens} tokens always in context", color: :cyan )] result << over_budget_line(guidelines) if tokens > TOTAL_WARN_TOKENS result end |