Skip to content

[Phase 2] Performance Optimizations #50

Description

@SBFRF

Overview

Implement performance optimizations for the murgtools/getdata module.


2.1 Cache Server Detection

Move server detection from getnc() to module-level with caching. Currently re-runs socket operations on every call.

Problem: Every getnc() call runs socket operations to detect FRF vs external network.

Solution: Cache at module load with thread-safe implementation.


2.2 Convert Lookup Tables to Dictionaries

Replace 144-line if-elif chain in _waveGaugeURLlookup() with O(1) dictionary lookup.

Methods to update:

  • _waveGaugeURLlookup() (~144 lines)
  • _wlGageURLlookup() (~56 lines)

2.3 Add Dataset Caching with TTL

Add simple cache for getnc() results (5-minute TTL default) to avoid redundant network calls.


2.4 Consolidate Try-Except Fallback Pattern

Create helper function for the 40+ duplicate FRF/CHL server fallback patterns:

def _fetch_with_fallback(self, primary_url, fallback_url, error_message=None):
    """Fetch dataset with automatic fallback from FRF to CHL server."""
    try:
        return nc.Dataset(primary_url)
    except IOError:
        try:
            return nc.Dataset(fallback_url)
        except IOError:
            if error_message:
                print(error_message)
            return None

Files to Modify

  • murgtools/getdata/getDataFRF.py

Acceptance Criteria

  • 2.1 Server detection cached at module level
  • 2.2 Lookup tables converted to dictionaries
  • 2.3 Dataset caching with TTL implemented
  • 2.4 Fallback pattern consolidated into helper
  • All existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions