Repository: nautechsystems/nautilus_trader
File: nautilus_trader/live/execution_engine.py (Python)

Code before:
        self,
        mass_status: ExecutionMassStatus,
    ) -> bool:
        self._log.debug(f"<--[RPT] {mass_status}")
        self.report_count += 1

        self._log.info(
            f"Reconciling ExecutionMassStatus for {mass_status.venue}",
            color=LogColor.BLUE,
        )

        # Adjust fills for instruments with incomplete first lifecycles
        # Start with original orders and fills
        final_orders = dict(mass_status._order_reports)
        final_fills = dict(mass_status._fill_reports)

        for instrument_id in mass_status.position_reports.keys():
            # Respect reconciliation_instrument_ids filter
            if not self._consider_for_reconciliation(instrument_id):
                self._log.debug(
                    f"Skipping fill adjustment for {instrument_id}: "
                    f"not in `reconciliation_instrument_ids` include list",
                )
                continue

            self._log.info(
                f"Attempting to adjust fills for {instrument_id}",
                LogColor.BLUE,
            )
            instrument = self._cache.instrument(instrument_id)
            if instrument:
                self._log.info(
                    f"Calling adjust_fills_for_partial_window for {instrument_id}",
                    LogColor.BLUE,
                )
                adjusted_orders_for_instrument, adjusted_fills_for_instrument = (
                    adjust_fills_for_partial_window(
                        mass_status,
                        instrument,
                        self._log,
                    )
                )

                # Remove old orders and fills for this instrument
                for venue_order_id in list(final_orders.keys()):
                    order = final_orders[venue_order_id]
                    if order.instrument_id == instrument_id:
                        del final_orders[venue_order_id]

                for venue_order_id in list(final_fills.keys()):
                    fills = final_fills[venue_order_id]

Review comment (performance):
I suggest we handle the `None` case here, something like:

```python
instrument = self._cache.instrument(instrument_id)
if not instrument:
    continue
```

Code after:
        self,
        mass_status: ExecutionMassStatus,
    ) -> bool:
        self._log.debug(f"<--[RPT] {mass_status}")
        self.report_count += 1

        self._log.info(
            f"Reconciling ExecutionMassStatus for {mass_status.venue}",
            color=LogColor.BLUE,
        )

        # Adjust fills for instruments with incomplete first lifecycles
        # Start with original orders and fills
        final_orders = dict(mass_status._order_reports)
        final_fills = dict(mass_status._fill_reports)

        reconciliation_instruments: list[Instrument] = []
        for instrument_id in mass_status.position_reports.keys():
            # Respect reconciliation_instrument_ids filter
            if not self._consider_for_reconciliation(instrument_id):
                self._log.debug(
                    f"Skipping fill adjustment for {instrument_id}: "
                    f"not in `reconciliation_instrument_ids` include list",
                )
                continue
            reconciliation_instruments.append(self._cache.instrument(instrument_id))

        self._log.debug(
            f"Attempting to adjust fills for {len(reconciliation_instruments)} instruments",
            LogColor.BLUE,
        )
        adjusted_results = adjust_fills_for_partial_window(
            mass_status,
            reconciliation_instruments,
            self._log,
        )
        self._log.debug(
            f"Updating adjusted fills for {len(reconciliation_instruments)} instruments",
            LogColor.BLUE,
        )

        for instrument_id, (adjusted_orders_for_instrument, adjusted_fills_for_instrument) in adjusted_results.items():
            # Remove old orders and fills for this instrument
            for venue_order_id in list(final_orders.keys()):
                order = final_orders[venue_order_id]
                if order.instrument_id == instrument_id:
                    del final_orders[venue_order_id]

            for venue_order_id in list(final_fills.keys()):
                fills = final_fills[venue_order_id]
                if fills and fills[0].instrument_id == instrument_id: