Commit c59f86b
authored
fix: avoid linear objectHas scans for large inline imports (#1070)
Motivation:
PR #1061 was closed against the obsolete `fixjson` base, but the issue
still needs a clean PR on the current upstream `master`. PR #1060 added
the `InlineScanMax` fallback for `valueRaw`, yet repeated
`std.objectHas` / `std.objectHasAll` checks over large imported
strict-JSON objects still reached `containsVisibleKey` / `containsKey`
and scanned uncapped inline field arrays. That kept membership-heavy
workloads at O(N^2).
Modification:
- Rebase the PR #1061 follow-up onto current `upstream/master`
(`1db39dde`).
- Apply `Obj.InlineScanMax` to `Val.Obj.containsKey` and
`Val.Obj.containsVisibleKey`, so large inline objects fall through to
the existing lazy `getValue0` `LinkedHashMap` path.
- Reuse `Obj.InlineScanMax` in inline-object producers, keeping
construction and lookup thresholds on one source of truth.
- Add a benchmark regression covering repeated `std.objectHas` /
`std.objectHasAll` calls over imported JSON object fields.
Result:
| Benchmark | Current `master` | This branch | Change |
| --- | ---: | ---: | ---: |
| repeated `std.objectHas` / `std.objectHasAll` over large imported JSON
object fields | `97.942 ms/op` | `21.117 ms/op` | `4.64x` faster
(`-78%`) |
Large inline imported objects now pay one lazy map build above the scan
threshold, then reuse O(1) map probes for repeated membership checks.
Small inline objects keep the cheap linear scan path.
References:
- Replaces #1061.
- Follow-up to #1060.1 parent dda53fa commit c59f86b
5 files changed
Lines changed: 25 additions & 10 deletions
File tree
- bench/resources/sjsonnet_suite
- sjsonnet/src/sjsonnet
- stdlib
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1783 | 1783 | | |
1784 | 1784 | | |
1785 | 1785 | | |
1786 | | - | |
| 1786 | + | |
1787 | 1787 | | |
1788 | 1788 | | |
1789 | 1789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1816 | 1816 | | |
1817 | 1817 | | |
1818 | 1818 | | |
1819 | | - | |
1820 | | - | |
1821 | | - | |
1822 | | - | |
1823 | | - | |
1824 | | - | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
1825 | 1824 | | |
1826 | 1825 | | |
1827 | 1826 | | |
| |||
2301 | 2300 | | |
2302 | 2301 | | |
2303 | 2302 | | |
2304 | | - | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
2305 | 2306 | | |
2306 | 2307 | | |
2307 | 2308 | | |
| |||
2319 | 2320 | | |
2320 | 2321 | | |
2321 | 2322 | | |
2322 | | - | |
| 2323 | + | |
2323 | 2324 | | |
2324 | 2325 | | |
2325 | 2326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
0 commit comments