Code refactoring#35
Conversation
Signed-off-by: Andrei Shkrob <github@shkrob.dev>
894ea0f to
7b1e034
Compare
fixed |
|
|
||
| # Drawing style constants - stored as strings for format independence | ||
| self.dr_linecaps: Dict[str, str] = { | ||
| 'none': 'butt', |
| if data.get('text_stroke_color', 0) != 0: | ||
| sh_proto.text_stroke_color = data['text_stroke_color'] | ||
|
|
||
| return sh_proto |
There was a problem hiding this comment.
The implementation looks super slow.
# Move this outside the method to avoid re-allocating the tuple on every call
SHIELD_FIELDS = (
'height', 'color', 'stroke_color', 'priority',
'min_distance', 'text_color', 'text_stroke_color'
)
def _build_shieldrule(self, data: Optional[Dict[str, Any]]) -> Optional[ShieldRuleProto]:
"""Build ShieldRuleProto from dictionary with optimized lookups."""
if not data:
return None
sh_proto = ShieldRuleProto()
# Use a loop to reduce code size and keep the logic DRY.
# We use data.get() once to avoid the double lookup.
for field in SHIELD_FIELDS:
# This single lookup is O(1). val is retrieved once.
val = data.get(field, 0)
if val != 0:
setattr(sh_proto, field, val)
return sh_protoThere was a problem hiding this comment.
call it explicitly protobuf_serializer.py?
| libkomwm.MULTIPROCESSING = False | ||
| prio_ranges_orig = deepcopy(libkomwm.prio_ranges) |
There was a problem hiding this comment.
What was the use-case for these options?
There was a problem hiding this comment.
MULTIPROCESSING flags enables paraller processing of CSS rules. But on practice enabling it doesn't give signifficant improvements. Generating of drules takes less than 2 second. And adding paralellisation speed up is insignifficant.
There was a problem hiding this comment.
2 seconds is still too much. There is a plan to fix/revive Map Style Designer in the repo, it should regenerate map style on every edit/change, to immediately see the difference on the map.
| def __init__(self): | ||
| """Initialize the serializer.""" | ||
| self.linecap_map = { | ||
| 'none': LineCap.BUTTCAP, |
Behold, this is 99.99% AI-generated slop.
The most important change here is
drules_serializer.py. The code doesn't use pbf structs directly anymore. Serialization is moved into a separate file. This will be helpful if/when we switch to different library. For example https://github.com/google/flatbuffersThe code was tested and it produces the same output