Repository navigation
refactor(pulse): decompose monolithic core, optimize render allocations, and modularize test suite - #2
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors the core charting package following Go best practices, Single Responsibility Principle (SRP), and memory optimization guidelines:
Monolithic File Decomposition:
pulse.go(1,305 lines) into 8 focused, single-responsibility modules:pulse.go(318 lines): CoreModelstate, streaming window (Push,PushSeries), andChartgetters/setters.view.go(115 lines):View()orchestrator,fmt.Stringer, and tick label calculation.options.go(98 lines): Functional constructor options (With...).event.go(150 lines): Timeline events, aging, pruning,EventsBox(), and shared pin/guideline rendering.legend.go(37 lines): Multi-series legend presentation (Legend(),LegendBox()).renderer.go(161 lines): Rendering contracts, coordinate math (spanOf,normOf,tickRowOf), and grid assembler.renderer_lines.go(254 lines): Box-drawing curve engine, glyph masks, shaded and tinted fills.renderer_braille.go(252 lines): Braille dot matrix and Catmull-Rom spline interpolation.DRY Event Rendering:
▼,🚀,⚡) and vertical guidelines (┆) into shared helpers (eventsByColumn,renderEventPin,renderEventGuideline).LinesRendererandBrailleRenderer.Performance & Memory Allocations:
RenderContextnow passes slice references directly (SeriesData [][]float64), eliminating redundantmake([]float64)andcopy()calls per series on every frame.makeCells[T]to use a single continuous 1D buffer (make([]T, h*w)) with slice headers. Drops heap allocations by 76+ on every call toView().Defensive Range Normalization & Styling Constants:
min > max) inNewandSetRange.DefaultEventColor(#7dcfff) to replace scattered color string literals.Benchmark Suite:
pulse_bench_test.gocoveringView()acrossModeLines,TintedFill, andModeBraille, plusPush,LegendBox, andEventsBoxwith allocation tracking (b.ReportAllocs()).Test Suite Modularization:
pulse_test.go(673 lines) into domain test suites:event_test.go(132 lines): sliding window aging, off-screen pruning,EventsBox.legend_test.go(39 lines):Legend()andLegendBox().renderer_test.go(274 lines): grid lines, fill modes, tinted and solid area fills, line styles, label widths.pulse_test.go(237 lines): core model buffer, multi-series, range normalization, and tick sorting.Type of Change
Checklist
gofmt,go vet).go test -race ./...).