lambdaclass / lambdaclass/lambda_compiler_kit
perf: refactor rejectDuplicates in Parser.lean to avoid redundant sort and O(n²) insertion
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Problem
SortedKVs.ofListWithPolicy .rejectDuplicates in Lck/Json/Parser.lean does two passes:
hasDuplicateKeysList: sorts the list (mergeSort, O(n log n)) then scans adjacent pairsSortedKVs.ofList: builds the sorted structure via repeatedinsert(O(n) each → O(n²) total)
Total cost is O(n log n) + O(n²) = O(n²) with a hidden constant from sorting twice.
Suggested Fix
Add a SortedKVs.fromSortedList helper that builds the sorted structure from a pre-sorted list in O(n), then combine the duplicate check and structure construction into a single pass over the mergeSort output. This would bring the rejectDuplicates path to O(n log n) overall.
The same refactor would help firstWins and lastWins paths in ofList/ofListLastWins.
Complexity
Moderate: requires a new Syntax.lean helper and corresponding proof in Proofs.lean.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Lck/Json/Parser.lean by reading SortedKVs.ofListWithPolicy, hasDuplicateKeysList, ofList, and ofListLastWins. Then inspect the existing structure in Syntax.lean and related proofs in Proofs.lean. Done means a fromSortedList helper enables one mergeSort pass for rejectDuplicates, firstWins, and lastWins while preserving the corresponding proofs and O(n log n) behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100