perf(execution): build component association indexes only when needed

This commit is contained in:
阿白叔 committed 2026-10-19 10:13:37 +08:00
1 parent 2ad36ba45d
commit 8fe82c3124
3 files changed
+93 -15

No files matched your search

@@ -458,6 +458,54 @@ Require Not QP_NativeMutationPossible,"no native mutation"
''')
def test_zero_match_does_not_read_unused_component_geometry(tmp_path, monkeypatch):
counted = EXTRA.replace('Public UID, Refdes, Orientation, Scale, Attributes, AddCount',
'Public UID, Refdes, Orientation, Scale, Attributes, AddCount, LocationReads')
counted = counted.replace('Set GetLocation=Point',
'LocationReads=LocationReads+1\n Set GetLocation=Point', 1)
monkeypatch.setattr(f'{__name__}.EXTRA', counted)
run_vbs(tmp_path, 'preserve', '''
QP_Fso.DeleteFile SnapshotPath
Comp.LocationReads=0
QPCaptureAndSelect Command,SnapshotPath
Require QPReadState(QP_Fso.BuildPath(QP_Root,"status.tsv"),"value-job")="no_match","no-match state"
Require Comp.LocationReads=0,"no-match read geometry for an index that is never consumed"
Require Not QP_Fso.FileExists(SnapshotPath),"no-match generated a snapshot"
''')
def test_component_lookup_reads_fallback_geometry_only_when_needed(tmp_path, monkeypatch):
counted = EXTRA.replace('Public UID, Refdes, Orientation, Scale, Attributes, AddCount',
'Public UID, Refdes, Orientation, Scale, Attributes, AddCount, LocationReads')
counted = counted.replace('Set GetLocation=Point',
'LocationReads=LocationReads+1\n Set GetLocation=Point', 1)
monkeypatch.setattr(f'{__name__}.EXTRA', counted)
run_vbs(tmp_path, 'preserve', '''
Dim Records, Record, Candidate
Set Records=QPReadSnapshot(SnapshotPath)
Set Record=Records.Item("components").Item("0")
QPInvalidateComponentIndex
Comp.LocationReads=0
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Candidate Is Comp,"UID lookup returned wrong component"
Require Comp.LocationReads=0,"UID lookup eagerly read fallback geometry"
Record("uid")="missing"
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Candidate Is Comp,"refdes fallback returned wrong component"
Require Comp.LocationReads=0,"refdes lookup eagerly read location fallback"
Record("refdes")="missing"
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Candidate Is Comp,"location fallback returned wrong component"
Require Comp.LocationReads=1,"location fallback did not read geometry exactly once"
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Comp.LocationReads=1,"same read context rebuilt its fallback index"
QPInvalidateComponentIndex
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Candidate Is Comp,"fresh location fallback returned wrong component"
Require Comp.LocationReads=2,"invalidated index reused stale geometry"
''')
def test_pin_index_avoids_repeated_full_sheet_queries(tmp_path):
run_vbs(tmp_path, 'part_number', '''
QPInvalidatePinIndex
+6 -1
View File
@@ -445,7 +445,8 @@ WScript.Echo CStr(InStr(Text, "G" & vbTab & "note" & vbTab) > 0)
@pytest.mark.parametrize('read_failure', [False, True])
def test_all_match_capture_protects_unselected_and_does_not_hide_pn_error(tmp_path, read_failure):
@pytest.mark.parametrize('exact_scope', [False, True])
def test_capture_protects_unselected_and_does_not_hide_target_pn_error(tmp_path, read_failure, exact_scope):
snapshot = str(tmp_path / 'captured.tsv')
output = run_vbs(tmp_path, UNTOUCHED_ROUTINES + ['QPCaptureAndSelect', 'QPSnapshotComponent',
'QPCommandTargets', 'QPBooleanText', 'QPLogField'], '''
@@ -459,8 +460,12 @@ QP_App.ActiveView.Components.Add Comp, True: QP_App.ActiveView.Components.Add Ot
Set Pin = New FakePin: Set Pin.Component = Comp: Pin.Number = "1": Pin.X = 0: Pin.Y = 0
Set Pin.Connection = Nothing: QP_App.ActiveView.Pins.Add Pin, True
Comp.RaiseOnFind = ''' + ('True' if read_failure else 'False') + '''
Other.RaiseOnFind = ''' + ('True' if exact_scope else 'False') + '''
Set Command = CreateObject("Scripting.Dictionary")
Command.Add "job_id", "test": Command.Add "old_part_number", "OLD": Command.Add "new_part_number", "NEW"
''' + ('''Command.Add "target_scope", "targets"
Command.Add "target_selectors", QPEncode("u1" & Chr(31) & "R1" & Chr(31))
''' if exact_scope else '') + '''
On Error Resume Next
QPCaptureAndSelect Command, "''' + snapshot + '''"
WScript.Echo Err.Number