Skip to content

Code refactoring#35

Open
AndrewShkrob wants to merge 1 commit intoorganicmaps:masterfrom
AndrewShkrob:dev/refactoring
Open

Code refactoring#35
AndrewShkrob wants to merge 1 commit intoorganicmaps:masterfrom
AndrewShkrob:dev/refactoring

Conversation

@AndrewShkrob
Copy link
Copy Markdown
Member

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/flatbuffers

The code was tested and it produces the same output

Copy link
Copy Markdown
Member

@biodranik biodranik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integration-tests/full_drules_gen.py is broken now

@strump WDYT?

Signed-off-by: Andrei Shkrob <github@shkrob.dev>
@AndrewShkrob
Copy link
Copy Markdown
Member Author

integration-tests/full_drules_gen.py is broken now

fixed


# Drawing style constants - stored as strings for format independence
self.dr_linecaps: Dict[str, str] = {
'none': 'butt',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct?

Comment thread src/drules_serializer.py
if data.get('text_stroke_color', 0) != 0:
sh_proto.text_stroke_color = data['text_stroke_color']

return sh_proto
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_proto

Comment thread src/drules_serializer.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it explicitly protobuf_serializer.py?

Comment on lines -31 to -32
libkomwm.MULTIPROCESSING = False
prio_ranges_orig = deepcopy(libkomwm.prio_ranges)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the use-case for these options?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/drules_serializer.py
def __init__(self):
"""Initialize the serializer."""
self.linecap_map = {
'none': LineCap.BUTTCAP,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants