[OVERKILL (DO NOT MERGE)]perf: lazy color index rebuild for large codebases - #8
Open
lmn451 wants to merge 13 commits into
Open
[OVERKILL (DO NOT MERGE)]perf: lazy color index rebuild for large codebases#8lmn451 wants to merge 13 commits into
lmn451 wants to merge 13 commits into
Conversation
Extract flag resolution logic into dedicated helper functions in new flags.rs module. This reduces boilerplate per flag from ~20 lines to ~3 lines, making it easier to add new feature flags. Changes: - Add src/flags.rs with reusable flag_bool, flag_bool_simple, flag_opt, flag_enum helpers - Refactor runtime_config.rs to use the new helpers - Pass runtime_config to code_actions_for_replaceable_literal_colors - Add --no-suggest-add-fallback and --no-suggest-exact-color-variables flags for controlling code action suggestions
Document all available feature flags in: - CHANGELOG.md: Add Unreleased section with new flags - AGENTS.md: Add flags.rs to source layout and expand configuration management section with flag architecture and full flag table - README.md: Add Configuration section with flag table and examples
…efinitions Filters out replacement suggestions where the literal color is already part of the variable's own value range. This prevents suggesting replacing #ffd166 with --accent-2 when editing: --accent-2: #ffd166;
- Change literal_colors from HashMap<Uri, Vec<>> to HashMap<Uri, HashMap<u32, Vec<>>> - Add get_literal_colors_at_position() for O(1) line lookup - Update literal_color_under_cursor() to use position-based lookup - get_document_literal_colors() still returns flattened vec for compatibility Lookup complexity: O(n) -> O(1) hash + O(k) where k = colors on line
- Add color_occurrence_uris index to track documents with literal colors - Modify revalidate_affected_documents to optionally include color documents - Use selective revalidation on did_change instead of validating all docs - This improves performance in large workspaces with many open files
Replaces immediate full rebuild on every document change with lazy rebuild pattern using dirty flag. Changes: - Add color_variables_dirty AtomicBool flag - Add mark_color_index_dirty() - O(1) set flag - Add ensure_color_index_valid() - rebuild if dirty - Update lsp_server to use lazy pattern Benchmark (100k vars with chains): - Rebuild time: ~479ms (unchanged) - Rebuild count: reduced from O(N) to O(1) per validation cycle Note: For typical projects with <1000 vars, rebuild time is ~2ms which is imperceptible. This optimization mainly helps in large codebases with many variables and rapid document changes. Tests: - test_color_index_rebuild_performance_100k_vars - test_lazy_rebuild_batches_multiple_changes - test_lazy_rebuild_reduces_rebuild_count - test_lazy_rebuild_batches_document_changes
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.
Summary
Replaces immediate full rebuild on every document change with a lazy rebuild pattern using a dirty flag.
Motivation: For very large codebases (100k+ CSS variables), frequent rebuilds could impact performance.
Changes:
Benchmark (100k vars with chains):
Note: For typical projects (<1000 vars), rebuild time is ~2ms which is imperceptible. This optimization mainly helps in edge cases with many variables and rapid document changes.
Tests added:
Closes #TODO