Skip to content

Refactor Metric class to separate definition from value and optimize memory usage #155

@AumPatel1

Description

@AumPatel1

The Metric class currently mixes two concerns:

  • Metric definition (what the metric is: name, comparison method)
  • Metric value(a specific measurement: the numeric value)

This causes:

  • Memory inefficiency: Each solution creates a new MetricComparator instance even when using the same comparison method
  • Conceptual confusion: The class violates single responsibility principle
  • TODO comment in code indicates this needs refactoring (line 101 in metric.py)

Expected Behavior

  • Separate metric type definition from metric value
  • Share comparator instances across all solutions using the same comparison method
  • Reduce memory usage by reusing comparator objects
  • Maintain full backward compatibility with existing API

Impact
When running with max_iterations=10, we create 10 identical MetricComparator objects instead of sharing one. This wastes memory and makes the code harder to maintain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions