Skip to content

Commit 04d648d

Browse files
committed
mps-cli - mini cleanups
1 parent e82fdd8 commit 04d648d

2 files changed

Lines changed: 12 additions & 43 deletions

File tree

mps-cli-py/src/mpscli/model/builder/SModelBuilderBinaryPersistency.py

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ def _load_header(self, reader: ModelInputStream) -> int:
150150
return version, _model_uuid, _model_name
151151

152152
def _read_model_reference_v2(self, reader: ModelInputStream):
153-
"""
154-
Consume a V2 SModelReference. Returns (uuid_str, name) or (None, None).
155-
"""
156153
kind = reader.read_u8()
157154
# NULL model reference
158155
if kind == 0x70:
@@ -169,32 +166,21 @@ def _read_model_reference_v2(self, reader: ModelInputStream):
169166
return uuid_str, name
170167

171168
def _read_model_id(self, reader: ModelInputStream):
172-
"""Consume a V3 SModelId (may be uuid-based or string-based)."""
173169
kind = reader.read_u8()
174-
if kind == 0x70: # NULL
170+
# NULL
171+
if kind == 0x70:
175172
return None
176-
if kind == 0x48: # uuid-based
173+
# uuid-based
174+
if kind == 0x48:
177175
high, low = reader.read_uuid()
178176
return f"r:{high:016x}{low:016x}"
179-
elif kind == 0x47: # string-based
177+
# string-based
178+
elif kind == 0x47:
180179
return reader.read_string()
181-
return None # unknown kind
180+
# unknown kind
181+
return None
182182

183183
def _load_model_properties(self, reader: ModelInputStream, version: int):
184-
"""
185-
V2 format has no dependency format byte -
186-
loadUsedLanguagesV2 — u16 count, each is uuid + string
187-
loadModuleRefList — engaged languages
188-
loadModuleRefList — devkits
189-
loadImports V2 — u32 count, each is model_ref + i32
190-
191-
V3 format has dependency format byte:
192-
readByte DEPENDENCY_V1
193-
loadUsedLanguagesV3 — u16 count, each is readLanguage + i32
194-
loadEngagedLanguages — u16 count, each is readLanguage
195-
loadModuleRefList — devkits
196-
loadImports V3 — u32 count, each is model_ref
197-
"""
198184
if version == _V2:
199185
self._load_used_languages_v2(reader)
200186
# engaged languages
@@ -257,21 +243,6 @@ def _load_imports(self, reader: ModelInputStream, version: int):
257243
self.index_2_imported_model_uuid[str(i + 1)] = model_id or ""
258244

259245
def _read_model_reference(self, reader: ModelInputStream):
260-
"""
261-
Reads a SModelReference in V2 binary format where:
262-
outer kind byte:
263-
0x70 → NULL (nothing more to read)
264-
0x07 → non-null, read sub-kind next
265-
sub-kind byte:
266-
0x28 → regular (uuid-based SModelId):
267-
uuid_high (u64) + uuid_low (u64)
268-
string model_name
269-
string stereotype/null (maybe 0x70, remove after debugging)
270-
0x26 → foreign (string-based SModelId, e.g. java stubs):
271-
string model_id (e.g. "java:java.lang")
272-
string model_name (e.g. "java.lang@java_stub")
273-
module_ref (declaring module)
274-
"""
275246
kind = reader.read_u8()
276247
# NULL model reference
277248
if kind == 0x70:
@@ -301,7 +272,6 @@ def _read_model_reference(self, reader: ModelInputStream):
301272
return model_id
302273

303274
def _skip_to_marker(self, reader: ModelInputStream, marker: int):
304-
# Sliding-window scan until 'marker' (4-byte big-endian) is found and consumed.
305275
target = marker.to_bytes(4, "big")
306276
start = reader.pos
307277
while reader.pos + 4 <= len(reader.data):

mps-cli-py/src/mpscli/model/builder/SSolutionsRepositoryBuilder.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
44
Performance optimizations:
55
1. Lazy jar scanning: peek inside each zip for .msd before extracting.
6-
Around 80% of jars (those without .msd) are skipped entirely so no extraction,no scan, no cleanup.
6+
Looks like around 80% of jars (those without .msd) are skipped entirely so no extraction and no scan.
77
This is identical to the old code because the original code also only discovered .mpb files through the .msd - models/
88
chain and a jar without .msd was always skipped.
9-
2. Parallel jar processing: extract/scan/parse/cleanup in a thread pool.
10-
i/o-bound work so ThreadPoolExecutor is ideal.
11-
3. Persistent disk cache: parsed SModel objects moved to mps_cli_cache.
12-
and unchanged files load in milliseconds and cache is invalidated automatically when a file changes.
9+
2. Parallel jar processing: extract/scan/parse/cleanup in a thread pool (i/o-bound work) so ThreadPoolExecutor is ideal.
10+
3. Persistent disk cache: parsed SModel objects moved to mps_cli_cache and unchanged files load in probably milliseconds
11+
and cache is invalidated automatically when a file changes.
1312
"""
1413

1514
from timeit import default_timer as timer

0 commit comments

Comments
 (0)