Commit 84a93eb254 for aom

commit 84a93eb254c3150e065331549af06ead40b4bf4a
Author: Lin Zheng <linzhen@google.com>
Date:   Thu Nov 12 18:05:58 2026 +0000

    Optimize encoder speed features for all speeds

    Refine GOOD mode speed features for speed >= 3. Additionally, adjusted
    motion/partition search, warped motion vector refinement, rdmult and
    screen-content tools for all speed levels, achieving 4-5% vmaf_v1 gain,
    and 0.3-0.8% psnr1411 gain across all speeds, as well as a 9-10% speedup
    at speed 3 and a 1-2% speedup at speed 4.

    The bdrate and speed impact across multiple testsets are:

                         Q-mode                     VBR-mode
    speed         psnr1411 vmaf_v1 speedup    psnr1411 vmaf_v1 speedup
    ==================================================================
    0 {MEDIAN}    -0.1125 -4.0433  0.4075     -0.3542 -3.8388  0.6078
      {OVERALL}   -0.6933 -4.8617 -0.1985     -0.8476 -4.5104  1.8644
    ==================================================================
    1 {MEDIAN}    -0.1374 -4.1038  0.4962     -0.294  -3.7186  0.5376
      {OVERALL}   -0.539  -4.6484 -0.2518     -0.8038 -4.4346 -0.53
    ==================================================================
    2 {MEDIAN}    -0.052  -4.051   0.4156     -0.3662 -3.96    0.5258
      {OVERALL}   -0.4702 -4.7322  0.109      -0.7556 -4.5716  0.1284
    ==================================================================
    3 {MEDIAN}    -0.0668 -4.007   5.9664     -0.3388 -3.8032  5.7478
      {OVERALL}   -0.2256 -4.4506 10.396      -0.4492 -4.0886  8.8438
    ==================================================================
    4 {MEDIAN}    -0.1084 -4.7892  2.4034     -0.4416 -4.785   1.4982
      {OVERALL}   -0.2784 -5.1098  2.0956     -0.6194 -5.0548  1.0228
    ==================================================================

    STATS_CHANGED

    Change-Id: Ia8d673ce02a36a0f6bf1d9bd002afcd0520b54d1

diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 6a49c1127f..97cf2e9460 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -1022,6 +1022,38 @@ typedef struct macroblock {
   //! Superblock level distortion propagation factor.
   double rb;

+  //! Frame number (+1) for which the SB TPL log-cost cache in av1_get_cb_rdmult
+  //! was populated.
+  int cb_rdmult_cur_frame_num;
+  //! Superblock MI row for which cb_rdmult_16x16 was precomputed.
+  int cb_rdmult_sb_row;
+  //! Superblock MI column for which cb_rdmult_16x16 was precomputed.
+  int cb_rdmult_sb_col;
+  //! GF group frame index for which cb_rdmult_16x16 was precomputed.
+  int cb_rdmult_sb_gf_idx;
+  //! Superblock delta-qindex offset used when precomputing cb_rdmult_16x16.
+  int cb_rdmult_sb_deltaq;
+  //! Frame base_qindex used when precomputing cb_rdmult_16x16.
+  int cb_rdmult_sb_base_q;
+  //! Base rdmult value for the superblock before TPL scaling.
+  int cb_rdmult_sb_base_rdmult;
+  //! Superblock distortion propagation factor rb used for cb_rdmult_16x16.
+  double cb_rdmult_sb_rb;
+  //! Superblock MI row for which per-TPL-block log costs were cached.
+  int cb_rdmult_costs_row;
+  //! Superblock MI column for which per-TPL-block log costs were cached.
+  int cb_rdmult_costs_col;
+  //! GF group frame index for which per-TPL-block log costs were cached.
+  int cb_rdmult_costs_gf_idx;
+  //! Cached per-TPL-unit coding-block rdmult values within the superblock.
+  int cb_rdmult_16x16[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
+  //! Cached weighted log own-distortion costs per TPL unit in the superblock.
+  double cb_intra_cost_16x16[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
+  //! Cached weighted log temporal-dependency costs per TPL unit in the SB.
+  double cb_mc_dep_cost_16x16[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
+  //! Cached TPL source-reference distortion weights per TPL unit in the SB.
+  double cb_cbcmp_16x16[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
+
   //! Energy in the current source coding block. Used to calculate \ref rdmult
   int mb_energy;
   //! Energy in the current source superblock. Used to calculate \ref rdmult
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 5d7e533e9e..a70b9cb6e7 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -372,6 +372,9 @@ static inline void setup_delta_q(AV1_COMP *const cpi, ThreadData *td,
                         ? current_qindex - cm->quant_params.base_qindex
                         : 0;
   x->rdmult_delta_qindex = current_qindex - cm->quant_params.base_qindex;
+  // Invalidate SB-level TPL cost and rdmult caches when starting a new SB.
+  x->cb_rdmult_costs_row = -1;
+  x->cb_rdmult_sb_row = -1;

   av1_set_offsets(cpi, tile_info, x, mi_row, mi_col, sb_size);
   xd->mi[0]->current_qindex = cm->delta_q_info.delta_q_present_flag
diff --git a/av1/encoder/encodeframe_utils.c b/av1/encoder/encodeframe_utils.c
index da625bbc7e..4c3d537444 100644
--- a/av1/encoder/encodeframe_utils.c
+++ b/av1/encoder/encodeframe_utils.c
@@ -98,6 +98,24 @@ void av1_set_saliency_map_vmaf_rdmult(const AV1_COMP *const cpi,

 // TODO(angiebird): Move this function to tpl_model.c
 #if !CONFIG_REALTIME_ONLY
+// Helper to compute weighted log-domain TPL costs for a single TPL block
+// (shared by the superblock cache and fallback path in av1_get_cb_rdmult).
+static inline void compute_tpl_block_log_costs(const TplDepFrame *tpl_frame,
+                                               const TplDepStats *this_stats,
+                                               double *intra_cost,
+                                               double *mc_dep_cost,
+                                               double *cbcmp_out) {
+  const double cbcmp = (double)this_stats->srcrf_dist;
+  const int64_t mc_dep_delta = RDCOST(
+      tpl_frame->base_rdmult, this_stats->mc_dep_rate, this_stats->mc_dep_dist);
+  double dist_scaled = (double)(this_stats->recrf_dist << RDDIV_BITS);
+  // Clamp to >= 1 to avoid log(0) / NaN when recrf_dist is zero.
+  dist_scaled = AOMMAX(dist_scaled, 1);
+  *intra_cost = log(dist_scaled) * cbcmp;
+  *mc_dep_cost = log(3 * dist_scaled + mc_dep_delta) * cbcmp;
+  *cbcmp_out = cbcmp;
+}
+
 int av1_get_cb_rdmult(const AV1_COMP *const cpi, MACROBLOCK *const x,
                       const BLOCK_SIZE bsize, const int mi_row,
                       const int mi_col) {
@@ -105,47 +123,154 @@ int av1_get_cb_rdmult(const AV1_COMP *const cpi, MACROBLOCK *const x,
   assert(IMPLIES(cpi->ppi->gf_group.size > 0,
                  cpi->gf_frame_index < cpi->ppi->gf_group.size));
   const int tpl_idx = cpi->gf_frame_index;
-  int deltaq_rdmult = set_rdmult(cpi, x, -1);
-  if (!av1_tpl_stats_ready(&cpi->ppi->tpl_data, tpl_idx)) return deltaq_rdmult;
-  if (cm->superres_scale_denominator != SCALE_NUMERATOR) return deltaq_rdmult;
-  if (cpi->oxcf.q_cfg.aq_mode != NO_AQ) return deltaq_rdmult;
-  if (x->rb == 0) return deltaq_rdmult;
+  if (!av1_tpl_stats_ready(&cpi->ppi->tpl_data, tpl_idx) ||
+      cm->superres_scale_denominator != SCALE_NUMERATOR ||
+      cpi->oxcf.q_cfg.aq_mode != NO_AQ || x->rb == 0) {
+    return set_rdmult(cpi, x, -1);
+  }

   TplParams *const tpl_data = &cpi->ppi->tpl_data;
-  TplDepFrame *tpl_frame = &tpl_data->tpl_frame[tpl_idx];
-  TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr;
+  const int block_mis_log2 = tpl_data->tpl_stats_block_mis_log2;
+  const int step = 1 << block_mis_log2;
+  const int mib_size = cm->seq_params->mib_size;
+  const int sb_mi_row = mi_row & ~(mib_size - 1);
+  const int sb_mi_col = mi_col & ~(mib_size - 1);
+  const int sb_grid = mib_size >> block_mis_log2;
+  const int cur_frame_num = cm->current_frame.frame_number + 1;
+
+  // Cache TPL log-domain costs and 16x16 rdmult values per superblock so
+  // repeated partition/mode evaluations within the same SB avoid recomputing
+  // TPL stats lookups, log(), and exp().
+  if (sb_grid <= MAX_TPL_BLK_IN_SB) {
+    // Stage 1: Populate per-TPL-block weighted log costs once per superblock.
+    if (x->cb_rdmult_cur_frame_num != cur_frame_num ||
+        x->cb_rdmult_costs_row != sb_mi_row ||
+        x->cb_rdmult_costs_col != sb_mi_col ||
+        x->cb_rdmult_costs_gf_idx != tpl_idx) {
+      const TplDepFrame *const tpl_frame = &tpl_data->tpl_frame[tpl_idx];
+      const TplDepStats *const tpl_stats = tpl_frame->tpl_stats_ptr;
+      const int tpl_stride = tpl_frame->stride;
+      for (int r = 0; r < sb_grid; ++r) {
+        const int row = sb_mi_row + (r << block_mis_log2);
+        for (int c = 0; c < sb_grid; ++c) {
+          const int col = sb_mi_col + (c << block_mis_log2);
+          const int idx = r * MAX_TPL_BLK_IN_SB + c;
+          if (row >= cm->mi_params.mi_rows || col >= cm->mi_params.mi_cols) {
+            x->cb_intra_cost_16x16[idx] = 0.0;
+            x->cb_mc_dep_cost_16x16[idx] = 0.0;
+            x->cb_cbcmp_16x16[idx] = 0.0;
+            continue;
+          }
+          const TplDepStats *const this_stats =
+              &tpl_stats[av1_tpl_ptr_pos(row, col, tpl_stride, block_mis_log2)];
+          compute_tpl_block_log_costs(
+              tpl_frame, this_stats, &x->cb_intra_cost_16x16[idx],
+              &x->cb_mc_dep_cost_16x16[idx], &x->cb_cbcmp_16x16[idx]);
+        }
+      }
+      x->cb_rdmult_cur_frame_num = cur_frame_num;
+      x->cb_rdmult_costs_row = sb_mi_row;
+      x->cb_rdmult_costs_col = sb_mi_col;
+      x->cb_rdmult_costs_gf_idx = tpl_idx;
+      x->cb_rdmult_sb_row = -1;
+    }
+
+    // Stage 2: Precompute per-unit rdmult whenever SB quantizer/rb changes.
+    if (x->cb_rdmult_sb_row != sb_mi_row || x->cb_rdmult_sb_col != sb_mi_col ||
+        x->cb_rdmult_sb_gf_idx != tpl_idx ||
+        x->cb_rdmult_sb_deltaq != x->rdmult_delta_qindex ||
+        x->cb_rdmult_sb_base_q != cm->quant_params.base_qindex ||
+        x->cb_rdmult_sb_rb != x->rb) {
+      const int base_rdmult = set_rdmult(cpi, x, -1);
+      x->cb_rdmult_sb_base_rdmult = base_rdmult;
+      for (int r = 0; r < sb_grid; ++r) {
+        for (int c = 0; c < sb_grid; ++c) {
+          const int idx = r * MAX_TPL_BLK_IN_SB + c;
+          const double cbcmp_base = x->cb_cbcmp_16x16[idx];
+          if (cbcmp_base == 0.0) {
+            x->cb_rdmult_16x16[idx] = base_rdmult;
+          } else {
+            const double rk = exp(
+                (x->cb_intra_cost_16x16[idx] - x->cb_mc_dep_cost_16x16[idx]) /
+                cbcmp_base);
+            const int rdmult = (int)(base_rdmult * (rk / x->rb));
+            x->cb_rdmult_16x16[idx] = AOMMAX(rdmult, 1);
+          }
+        }
+      }
+      x->cb_rdmult_sb_row = sb_mi_row;
+      x->cb_rdmult_sb_col = sb_mi_col;
+      x->cb_rdmult_sb_gf_idx = tpl_idx;
+      x->cb_rdmult_sb_deltaq = x->rdmult_delta_qindex;
+      x->cb_rdmult_sb_base_q = cm->quant_params.base_qindex;
+      x->cb_rdmult_sb_rb = x->rb;
+    }
+
+    const int mi_wide = mi_size_wide[bsize];
+    const int mi_high = mi_size_high[bsize];
+    // Blocks at or below TPL block granularity directly reuse the cached unit
+    // rdmult; larger blocks aggregate the cached log costs over covered units.
+    if (mi_wide <= step && mi_high <= step) {
+      if (mi_row >= cm->mi_params.mi_rows || mi_col >= cm->mi_params.mi_cols)
+        return x->cb_rdmult_sb_base_rdmult;
+      const int r_idx = (mi_row - sb_mi_row) >> block_mis_log2;
+      const int c_idx = (mi_col - sb_mi_col) >> block_mis_log2;
+      return x->cb_rdmult_16x16[r_idx * MAX_TPL_BLK_IN_SB + c_idx];
+    }
+
+    int deltaq_rdmult = x->cb_rdmult_sb_base_rdmult;
+    double intra_cost_base = 0;
+    double mc_dep_cost_base = 0;
+    double cbcmp_base = 0;
+    for (int row = mi_row; row < mi_row + mi_high; row += step) {
+      for (int col = mi_col; col < mi_col + mi_wide; col += step) {
+        if (row >= cm->mi_params.mi_rows || col >= cm->mi_params.mi_cols)
+          continue;
+        const int idx =
+            ((row - sb_mi_row) >> block_mis_log2) * MAX_TPL_BLK_IN_SB +
+            ((col - sb_mi_col) >> block_mis_log2);
+        intra_cost_base += x->cb_intra_cost_16x16[idx];
+        mc_dep_cost_base += x->cb_mc_dep_cost_16x16[idx];
+        cbcmp_base += x->cb_cbcmp_16x16[idx];
+      }
+    }
+    if (cbcmp_base == 0) return deltaq_rdmult;
+    const double rk = exp((intra_cost_base - mc_dep_cost_base) / cbcmp_base);
+    deltaq_rdmult = (int)(deltaq_rdmult * (rk / x->rb));
+    return AOMMAX(deltaq_rdmult, 1);
+  }
+
+  int deltaq_rdmult = set_rdmult(cpi, x, -1);
+  const TplDepFrame *const tpl_frame = &tpl_data->tpl_frame[tpl_idx];
+  const TplDepStats *const tpl_stats = tpl_frame->tpl_stats_ptr;

   const int mi_wide = mi_size_wide[bsize];
   const int mi_high = mi_size_high[bsize];

-  int tpl_stride = tpl_frame->stride;
+  const int tpl_stride = tpl_frame->stride;
   double intra_cost_base = 0;
   double mc_dep_cost_base = 0;
   double cbcmp_base = 0;
-  const int step = 1 << tpl_data->tpl_stats_block_mis_log2;

   for (int row = mi_row; row < mi_row + mi_high; row += step) {
     for (int col = mi_col; col < mi_col + mi_wide; col += step) {
       if (row >= cm->mi_params.mi_rows || col >= cm->mi_params.mi_cols)
         continue;

-      TplDepStats *this_stats = &tpl_stats[av1_tpl_ptr_pos(
-          row, col, tpl_stride, tpl_data->tpl_stats_block_mis_log2)];
-
-      double cbcmp = (double)this_stats->srcrf_dist;
-      int64_t mc_dep_delta =
-          RDCOST(tpl_frame->base_rdmult, this_stats->mc_dep_rate,
-                 this_stats->mc_dep_dist);
-      double dist_scaled = (double)(this_stats->recrf_dist << RDDIV_BITS);
-      intra_cost_base += log(dist_scaled) * cbcmp;
-      mc_dep_cost_base += log(3 * dist_scaled + mc_dep_delta) * cbcmp;
+      const TplDepStats *const this_stats =
+          &tpl_stats[av1_tpl_ptr_pos(row, col, tpl_stride, block_mis_log2)];
+      double intra_cost, mc_dep_cost, cbcmp;
+      compute_tpl_block_log_costs(tpl_frame, this_stats, &intra_cost,
+                                  &mc_dep_cost, &cbcmp);
+      intra_cost_base += intra_cost;
+      mc_dep_cost_base += mc_dep_cost;
       cbcmp_base += cbcmp;
     }
   }

   if (cbcmp_base == 0) return deltaq_rdmult;

-  double rk = exp((intra_cost_base - mc_dep_cost_base) / cbcmp_base);
+  const double rk = exp((intra_cost_base - mc_dep_cost_base) / cbcmp_base);
   deltaq_rdmult = (int)(deltaq_rdmult * (rk / x->rb));

   return AOMMAX(deltaq_rdmult, 1);
@@ -960,6 +1085,8 @@ int av1_get_q_for_deltaq_objective(AV1_COMP *const cpi, ThreadData *td,
           RDCOST(tpl_frame->base_rdmult, this_stats->mc_dep_rate,
                  this_stats->mc_dep_dist);
       double dist_scaled = (double)(this_stats->recrf_dist << RDDIV_BITS);
+      // Clamp to >= 1 to avoid log(0) / NaN when recrf_dist is zero.
+      dist_scaled = AOMMAX(dist_scaled, 1);
       intra_cost += log(dist_scaled) * cbcmp;
       mc_dep_cost += log(dist_scaled + mc_dep_delta) * cbcmp;
       mc_dep_reg += log(3 * dist_scaled + mc_dep_delta) * cbcmp;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 10167023ba..d8f1d003ab 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2501,6 +2501,15 @@ void av1_set_screen_content_options(AV1_COMP *cpi, FeatureFlags *features) {
   } else {
     estimate_screen_content(cpi, features);
   }
+
+  // Force screen content tools (palette and IntraBC) when firstpass
+  // identified the current KF group as static screen content.
+  if (cpi->ppi->twopass.is_static_sc_kf_group) {
+    features->allow_screen_content_tools = 1;
+    features->allow_intrabc = 1;
+    cpi->use_screen_content_tools = 1;
+    cpi->is_screen_content_type = 1;
+  }
 }

 static void init_motion_estimation(AV1_COMP *cpi) {
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index a5201682a1..b5c7f91e50 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -2166,6 +2166,14 @@ typedef struct {
    *                  av1_return_min_sub_pixel_mv
    */
   fractional_mv_step_fp *find_fractional_mv_step;
+  /*!
+   * Pointer to sub-pixel search function for TPL motion search.
+   */
+  fractional_mv_step_fp *find_fractional_mv_step_tpl;
+  /*!
+   * Pointer to sub-pixel search function for temporal filtering motion search.
+   */
+  fractional_mv_step_fp *find_fractional_mv_step_tf;
   /*!
    * Search site configuration for full-pel MV search.
    * search_site_cfg[SS_CFG_SRC]: Used in tpl, rd/non-rd inter mode loop, simple
diff --git a/av1/encoder/encoder_utils.c b/av1/encoder/encoder_utils.c
index d0fd7dbf6e..b3cccb30f7 100644
--- a/av1/encoder/encoder_utils.c
+++ b/av1/encoder/encoder_utils.c
@@ -636,6 +636,7 @@ static void process_tpl_stats_frame(AV1_COMP *cpi) {
             RDCOST(tpl_frame->base_rdmult, this_stats->mc_dep_rate,
                    this_stats->mc_dep_dist);
         double dist_scaled = (double)(this_stats->recrf_dist << RDDIV_BITS);
+        dist_scaled = AOMMAX(dist_scaled, 1);
         intra_cost_base += log(dist_scaled) * cbcmp;
         mc_dep_cost_base += log(dist_scaled + mc_dep_delta) * cbcmp;
         cbcmp_base += cbcmp;
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index 639eda748a..f805fc4220 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -454,8 +454,17 @@ typedef struct {

   int sr_update_lag;

+// First-pass thresholds for identifying static screen-content KF groups.
+#define STATIC_SC_KF_MEAN_ZM_THRESH 0.90
+#define STATIC_SC_KF_RATIO_THRESH 0.75
+#define STATIC_SC_KF_INTRA_SKIP_THRESH 0.15
+
   int kf_zeromotion_pct;
   int last_kfgroup_zeromotion_pct;
+  // Indicates whether the current KF group exhibits static screen-content
+  // characteristics (high zero-motion and intra-skip ratios) in firstpass
+  // stats.
+  int is_static_sc_kf_group;
   int extend_minq;
   int extend_maxq;
   /*!\endcond */
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index a15debb6f7..ec56704ff9 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -3576,6 +3576,8 @@ unsigned int av1_refine_warped_mv(MACROBLOCKD *xd, const AV1_COMMON *const cm,
   // Calculate the center position's error
   assert(av1_is_subpelmv_in_range(mv_limits, *best_mv));
   bestmse = compute_motion_cost(xd, cm, ms_params, bsize, best_mv);
+  unsigned int best_var =
+      bestmse - mv_err_cost_(best_mv, &ms_params->mv_cost_params);
   unsigned int dst_y_valid = 1;

   // MV search
@@ -3609,16 +3611,40 @@ unsigned int av1_refine_warped_mv(MACROBLOCKD *xd, const AV1_COMMON *const cm,
         if (!av1_find_projection(mbmi->num_proj_ref, pts, pts_inref, bsize,
                                  this_mv.row, this_mv.col, &mbmi->wm_params,
                                  mi_row, mi_col)) {
-          thismse = compute_motion_cost(xd, cm, ms_params, bsize, &this_mv);
-
-          if (thismse < bestmse) {
-            best_idx = idx;
-            best_wm_params = mbmi->wm_params;
-            best_num_proj_ref = mbmi->num_proj_ref;
-            bestmse = thismse;
-            dst_y_valid = 1;
+          const unsigned int this_mv_cost =
+              mv_err_cost_(&this_mv, &ms_params->mv_cost_params);
+          // If the projected warp parameters match the current best, the
+          // warped prediction pixels (and thus prediction distortion best_var)
+          // are identical; reuse best_var instead of recomputing warped MC.
+          const bool same_wm_params =
+              mbmi->wm_params.wmtype == best_wm_params.wmtype &&
+              mbmi->wm_params.invalid == best_wm_params.invalid &&
+              mbmi->wm_params.alpha == best_wm_params.alpha &&
+              mbmi->wm_params.beta == best_wm_params.beta &&
+              mbmi->wm_params.gamma == best_wm_params.gamma &&
+              mbmi->wm_params.delta == best_wm_params.delta &&
+              memcmp(mbmi->wm_params.wmmat, best_wm_params.wmmat,
+                     sizeof(best_wm_params.wmmat)) == 0;
+          if (same_wm_params) {
+            thismse = best_var + this_mv_cost;
+            if (thismse < bestmse) {
+              best_idx = idx;
+              best_num_proj_ref = mbmi->num_proj_ref;
+              bestmse = thismse;
+            }
           } else {
-            dst_y_valid = 0;
+            thismse = compute_motion_cost(xd, cm, ms_params, bsize, &this_mv);
+
+            if (thismse < bestmse) {
+              best_idx = idx;
+              best_wm_params = mbmi->wm_params;
+              best_num_proj_ref = mbmi->num_proj_ref;
+              bestmse = thismse;
+              best_var = thismse - this_mv_cost;
+              dst_y_valid = 1;
+            } else {
+              dst_y_valid = 0;
+            }
           }
         }
       }
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index dab1f13957..6626e20609 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -316,10 +316,27 @@ void av1_single_motion_search(const AV1_COMP *const cpi, MACROBLOCK *x,
             &full_ms_params, cpi, x, bsize, &ref_mv, smv.as_fullmv,
             src_search_site_cfg, search_method, fine_search_interval);

-        const int thissme =
-            av1_full_pixel_search(smv.as_fullmv, &full_ms_params, step_param,
-                                  cond_cost_list(cpi, cost_list), &this_best_mv,
-                                  &this_mv_stats, &this_second_best_mv);
+        // Narrow the full-pixel search range when TPL MV candidates strongly
+        // agree on the top starting MV.
+        int pme_step_param = step_param;
+        if (cpi->sf.mv_sf.reduce_search_range_using_tpl && total_weight > 0 &&
+            m == 0 && 4 * cand[0].weight > 3 * total_weight) {
+          if (cpi->sf.mv_sf.reduce_search_range_using_tpl >= 2) {
+            const int max_step = (ref > LAST_FRAME && ref != ALTREF_FRAME)
+                                     ? MAX_MVSEARCH_STEPS - 1
+                                     : MAX_MVSEARCH_STEPS - 2;
+            pme_step_param = AOMMAX(step_param, max_step);
+          } else if (cand[0].weight == total_weight) {
+            const int max_step = (ref > LAST_FRAME && ref != ALTREF_FRAME)
+                                     ? MAX_MVSEARCH_STEPS - 2
+                                     : MAX_MVSEARCH_STEPS - 3;
+            pme_step_param = AOMMAX(step_param, max_step);
+          }
+        }
+        const int thissme = av1_full_pixel_search(
+            smv.as_fullmv, &full_ms_params, pme_step_param,
+            cond_cost_list(cpi, cost_list), &this_best_mv, &this_mv_stats,
+            &this_second_best_mv);

         if (thissme < bestsme) {
           bestsme = thissme;
@@ -1078,10 +1095,24 @@ int_mv av1_simple_motion_search_sse_var(AV1_COMP *const cpi, MACROBLOCK *x,
   struct buf_2d backup_yv12;
   // ref_mv is used to calculate the cost of the motion vector
   const MV ref_mv = kZeroMv;
-  const int step_param =
+  int step_param =
       AOMMIN(cpi->mv_search_params.mv_step_param +
                  cpi->sf.part_sf.simple_motion_search_reduce_search_steps,
              MAX_MVSEARCH_STEPS - 2);
+  // Reduce the full-pixel search range when all TPL subblock MV candidates
+  // unanimously agree with start_mv.
+  if (cpi->sf.mv_sf.reduce_search_range_using_tpl >= 2 &&
+      x->sb_enc.tpl_data_count > 0) {
+    cand_mv_t hme_cand[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB + 1];
+    av1_zero(hme_cand);
+    hme_cand[0].fmv.as_fullmv = start_mv;
+    int hme_cnt = 1, hme_weight = 0;
+    get_mv_candidate_from_tpl(cpi, x, bsize, ref, hme_cand, &hme_cnt,
+                              &hme_weight);
+    if (hme_weight > 0 && hme_cand[0].weight == hme_weight) {
+      step_param = AOMMAX(step_param, MAX_MVSEARCH_STEPS - 2);
+    }
+  }
   int cost_list[5];
   const int ref_idx = 0;
   int bestsme;
diff --git a/av1/encoder/palette.c b/av1/encoder/palette.c
index 3946943668..9f3e6fdaa1 100644
--- a/av1/encoder/palette.c
+++ b/av1/encoder/palette.c
@@ -573,7 +573,11 @@ void av1_rd_pick_palette_intra_sby(
   }

   uint8_t *const color_map = xd->plane[0].color_index_map;
-  int color_thresh_palette = x->color_palette_thresh;
+  // Relax the distinct-color threshold for static screen-content KF groups so
+  // blocks with anti-aliased text/graphics are not prematurely pruned from
+  // luma palette search.
+  int color_thresh_palette =
+      cpi->ppi->twopass.is_static_sc_kf_group ? 256 : x->color_palette_thresh;
   // Allow for larger color_threshold for palette search, based on color,
   // scene_change, and block source variance.
   // Since palette is Y based, only allow larger threshold if block
@@ -812,7 +816,10 @@ void av1_rd_pick_palette_intra_sbuv(const AV1_COMP *cpi, MACROBLOCK *x,
   colors_threshold = colors_threshold_u > colors_threshold_v
                          ? colors_threshold_u
                          : colors_threshold_v;
-  if (colors_threshold > 1 && colors_threshold <= 64) {
+  // Relax chroma palette color threshold for static screen-content KF groups.
+  const int max_colors_thresh =
+      cpi->ppi->twopass.is_static_sc_kf_group ? 256 : 64;
+  if (colors_threshold > 1 && colors_threshold <= max_colors_thresh) {
     int r, c, n, i, j;
     const int max_itr = 50;
     int lb_u, ub_u, val_u;
diff --git a/av1/encoder/partition_strategy.c b/av1/encoder/partition_strategy.c
index 1689612898..3b33cd55fd 100644
--- a/av1/encoder/partition_strategy.c
+++ b/av1/encoder/partition_strategy.c
@@ -575,9 +575,27 @@ static inline void simple_motion_search_prune_part_features(

   // Rectangular subblocks
   if (!sms_tree->sms_rect_valid && features_to_get & FEATURE_SMS_RECT_FLAG) {
+    const int ref0 = ref_list[0];
+    // Reuse the sum of split subblocks' SMS features for a rectangular
+    // subblock when both split subblocks already have valid SMS results and
+    // nearly identical starting MVs (<= 1 pel).
+    const bool reuse_sms_split_for_rect =
+        cpi->sf.part_sf.reuse_sms_split_features_for_rect;
     // Horz subblock
     BLOCK_SIZE subsize = get_partition_subsize(bsize, PARTITION_HORZ);
     for (int r_idx = 0; r_idx < SUB_PARTITIONS_RECT; r_idx++) {
+      const SIMPLE_MOTION_DATA_TREE *const s0 = sms_tree->split[2 * r_idx];
+      const SIMPLE_MOTION_DATA_TREE *const s1 = sms_tree->split[2 * r_idx + 1];
+      if (reuse_sms_split_for_rect && s0->sms_none_valid &&
+          s1->sms_none_valid &&
+          abs(s0->start_mvs[ref0].row - s1->start_mvs[ref0].row) <= 1 &&
+          abs(s0->start_mvs[ref0].col - s1->start_mvs[ref0].col) <= 1) {
+        sms_tree->sms_rect_feat[2 * r_idx] =
+            s0->sms_none_feat[0] + s1->sms_none_feat[0];
+        sms_tree->sms_rect_feat[2 * r_idx + 1] =
+            s0->sms_none_feat[1] + s1->sms_none_feat[1];
+        continue;
+      }
       const int sub_mi_col = mi_col + 0;
       const int sub_mi_row = mi_row + r_idx * h_mi / 2;

@@ -590,6 +608,18 @@ static inline void simple_motion_search_prune_part_features(
     // Vert subblock
     subsize = get_partition_subsize(bsize, PARTITION_VERT);
     for (int r_idx = 0; r_idx < SUB_PARTITIONS_RECT; r_idx++) {
+      const SIMPLE_MOTION_DATA_TREE *const s0 = sms_tree->split[r_idx];
+      const SIMPLE_MOTION_DATA_TREE *const s1 = sms_tree->split[r_idx + 2];
+      if (reuse_sms_split_for_rect && s0->sms_none_valid &&
+          s1->sms_none_valid &&
+          abs(s0->start_mvs[ref0].row - s1->start_mvs[ref0].row) <= 1 &&
+          abs(s0->start_mvs[ref0].col - s1->start_mvs[ref0].col) <= 1) {
+        sms_tree->sms_rect_feat[4 + 2 * r_idx] =
+            s0->sms_none_feat[0] + s1->sms_none_feat[0];
+        sms_tree->sms_rect_feat[4 + 2 * r_idx + 1] =
+            s0->sms_none_feat[1] + s1->sms_none_feat[1];
+        continue;
+      }
       const int sub_mi_col = mi_col + r_idx * w_mi / 2;
       const int sub_mi_row = mi_row + 0;

diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 6ef6164aa6..ed81364c1d 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -3291,6 +3291,10 @@ static double get_kf_boost_score(AV1_COMP *cpi, double kf_raw_err,
   av1_zero(frame_stat);
   int i = 0, num_stat_used = 0;
   double boost_score = 0.0;
+  double sum_zm = 0.0;
+  double sum_intra_skip = 0.0;
+  int static_frame_count = 0;
+  int total_zm_frames = 0;
   const double kf_max_boost =
       cpi->oxcf.rc_cfg.mode == AOM_Q
           ? fclamp(rc->frames_to_key * 2.0, KF_MIN_FRAME_BOOST,
@@ -3307,12 +3311,18 @@ static double get_kf_boost_score(AV1_COMP *cpi, double kf_raw_err,

     // Monitor for static sections.
     // For the first frame in kf group, the second ref indicator is invalid.
+    const double cur_zm = get_zero_motion_factor(&frame_stat);
     if (i > 0) {
-      *zero_motion_accumulator =
-          AOMMIN(*zero_motion_accumulator, get_zero_motion_factor(&frame_stat));
+      *zero_motion_accumulator = AOMMIN(*zero_motion_accumulator, cur_zm);
     } else {
       *zero_motion_accumulator = frame_stat.pcnt_inter - frame_stat.pcnt_motion;
     }
+    sum_zm += (frame_stat.pcnt_inter - frame_stat.pcnt_motion);
+    sum_intra_skip += frame_stat.intra_skip_pct;
+    if ((frame_stat.pcnt_inter - frame_stat.pcnt_motion) >= MIN_ZERO_MOTION) {
+      ++static_frame_count;
+    }
+    ++total_zm_frames;

     // Not all frames in the group are necessarily used in calculating boost.
     if ((*sr_accumulator < (kf_raw_err * 1.50)) &&
@@ -3330,6 +3340,21 @@ static double get_kf_boost_score(AV1_COMP *cpi, double kf_raw_err,
       boost_score += frame_boost * zm_factor;
     }
   }
+  // Flag the KF group as static screen content if frames are predominantly
+  // zero-motion with significant flat/skip intra regions.
+  if (!use_avg_stat) {
+    if (total_zm_frames >= 10) {
+      const double mean_zm = sum_zm / total_zm_frames;
+      const double static_ratio = (double)static_frame_count / total_zm_frames;
+      const double mean_intra_skip = sum_intra_skip / total_zm_frames;
+      twopass->is_static_sc_kf_group =
+          (mean_zm >= STATIC_SC_KF_MEAN_ZM_THRESH &&
+           static_ratio >= STATIC_SC_KF_RATIO_THRESH &&
+           mean_intra_skip >= STATIC_SC_KF_INTRA_SKIP_THRESH);
+    } else {
+      twopass->is_static_sc_kf_group = 0;
+    }
+  }
   return boost_score;
 }

@@ -3372,6 +3397,7 @@ static void find_next_key_frame(AV1_COMP *cpi, FIRSTPASS_STATS *this_frame) {

   // KF is always a GF so clear frames till next gf counter.
   rc->frames_till_gf_update_due = 0;
+  twopass->is_static_sc_kf_group = 0;

   if (has_no_stats_stage(cpi)) {
     int num_frames_to_app_forced_key = detect_app_forced_key(cpi);
@@ -3679,6 +3705,11 @@ static void process_first_pass_stats(AV1_COMP *cpi,
     p_rc->avg_frame_qindex[INTER_FRAME] = tmp_q;
     p_rc->last_q[KEY_FRAME] = (tmp_q + cpi->oxcf.rc_cfg.best_allowed_q) / 2;
     p_rc->avg_frame_qindex[KEY_FRAME] = p_rc->last_q[KEY_FRAME];
+#if CONFIG_FPMT_TEST
+    p_rc->temp_avg_frame_qindex[INTER_FRAME] =
+        p_rc->avg_frame_qindex[INTER_FRAME];
+    p_rc->temp_avg_frame_qindex[KEY_FRAME] = p_rc->avg_frame_qindex[KEY_FRAME];
+#endif
   }

   if (cpi->twopass_frame.stats_in < twopass->stats_buf_ctx->stats_in_end) {
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 694c69ed79..2429263f2b 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -500,6 +500,11 @@ void av1_primary_rc_init(const AV1EncoderConfig *oxcf,
     p_rc->avg_frame_qindex[INTER_FRAME] =
         (worst_allowed_q + rc_cfg->best_allowed_q) / 2;
   }
+#if CONFIG_FPMT_TEST
+  for (int i = 0; i < FRAME_TYPES; i++) {
+    p_rc->temp_avg_frame_qindex[i] = p_rc->avg_frame_qindex[i];
+  }
+#endif
   p_rc->avg_q = av1_convert_qindex_to_q(rc_cfg->worst_allowed_q,
                                         oxcf->tool_cfg.bit_depth);
   p_rc->last_q[KEY_FRAME] = rc_cfg->best_allowed_q;
@@ -2572,6 +2577,7 @@ void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
   if (cpi->do_frame_data_update && !show_existing_between_parallel_frames &&
       cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE) {
     for (int i = 0; i < FRAME_TYPES; i++) {
+      p_rc->temp_avg_frame_qindex[i] = p_rc->avg_frame_qindex[i];
       p_rc->temp_last_q[i] = p_rc->last_q[i];
     }
     p_rc->temp_avg_q = p_rc->avg_q;
diff --git a/av1/encoder/ratectrl.h b/av1/encoder/ratectrl.h
index deea12d775..3f75b03153 100644
--- a/av1/encoder/ratectrl.h
+++ b/av1/encoder/ratectrl.h
@@ -431,6 +431,12 @@ typedef struct {
    */
   double temp_avg_q;

+  /*!
+   * Temporary variable used in simulating the delayed update of
+   * avg_frame_qindex.
+   */
+  int temp_avg_frame_qindex[FRAME_TYPES];
+
   /*!
    * Temporary variable used in simulating the delayed update of
    * last_q.
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 0414900f8b..f3ac421a05 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -3235,19 +3235,29 @@ static int64_t handle_inter_mode(

   // Do not prune the mode based on inter cost from tpl if the current ref frame
   // is the winner ref in neighbouring blocks.
-  int ref_match_found_in_above_nb = 0;
-  int ref_match_found_in_left_nb = 0;
-  if (prune_modes_based_on_tpl) {
-    ref_match_found_in_above_nb =
-        find_ref_match_in_above_nbs(cm->mi_params.mi_cols, xd);
-    ref_match_found_in_left_nb =
-        find_ref_match_in_left_nbs(cm->mi_params.mi_rows, xd);
+  const int ref_set = get_drl_refmv_count(x, mbmi->ref_frame, this_mode);
+  int tpl_prune_mask = 0;
+  if (prune_modes_based_on_tpl &&
+      !find_ref_match_in_above_nbs(cm->mi_params.mi_cols, xd) &&
+      !find_ref_match_in_left_nbs(cm->mi_params.mi_rows, xd)) {
+    for (int ref_mv_idx = 0; ref_mv_idx < ref_set; ++ref_mv_idx) {
+      if (prune_modes_based_on_tpl_stats(
+              inter_cost_info_from_tpl, refs, ref_mv_idx, this_mode,
+              cpi->sf.inter_sf.prune_inter_modes_based_on_tpl)) {
+        // Since TPL pruning thresholds are non-increasing with ref_mv_idx,
+        // pruning ref_mv_idx 0 guarantees all indices will be pruned; exit
+        // early before ref_mv_idx_to_search().
+        if (ref_mv_idx == 0 && ref_best_rd != INT64_MAX) {
+          return INT64_MAX;
+        }
+        mask_set_bit(&tpl_prune_mask, ref_mv_idx);
+      }
+    }
   }

   // First, perform a simple translation search for each of the indices. If
   // an index performs well, it will be fully searched in the main loop
   // of this function.
-  const int ref_set = get_drl_refmv_count(x, mbmi->ref_frame, this_mode);
   // Save MV results from first 2 ref_mv_idx.
   int_mv save_mv[MAX_REF_MV_SEARCH - 1][2];
   int best_ref_mv_idx = -1;
@@ -3287,18 +3297,13 @@ static int64_t handle_inter_mode(
     mode_info[ref_mv_idx].drl_cost = drl_cost;
     mode_info[ref_mv_idx].skip = 0;

-    if (!mask_check_bit(idx_mask, ref_mv_idx)) {
-      // MV did not perform well in simple translation search. Skip it.
+    if (!mask_check_bit(idx_mask, ref_mv_idx) ||
+        (ref_best_rd != INT64_MAX &&
+         mask_check_bit(tpl_prune_mask, ref_mv_idx))) {
+      // Skip MV if simple translation search or TPL model indicates it will
+      // not be beneficial.
       continue;
     }
-    if (prune_modes_based_on_tpl && !ref_match_found_in_above_nb &&
-        !ref_match_found_in_left_nb && (ref_best_rd != INT64_MAX)) {
-      // Skip mode if TPL model indicates it will not be beneficial.
-      if (prune_modes_based_on_tpl_stats(
-              inter_cost_info_from_tpl, refs, ref_mv_idx, this_mode,
-              cpi->sf.inter_sf.prune_inter_modes_based_on_tpl))
-        continue;
-    }
     av1_init_rd_stats(rd_stats);

     // Initialize compound mode data
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 40608050a1..41f90bf952 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -710,6 +710,31 @@ static void set_good_speed_features_lc_dec_framesize_independent(
   if (speed == 3) sf->hl_sf.weighted_chroma_distortion = 1;
 }

+// Returns an effective quantizer level across Q, CQ, and VBR/CBR modes for
+// driving quantizer-adaptive speed features.
+static inline int get_mode_q_level(const AV1_COMP *cpi) {
+  const RateControlCfg *const rc_cfg = &cpi->oxcf.rc_cfg;
+  if (rc_cfg->mode == AOM_Q) return rc_cfg->cq_level;
+  const RATE_CONTROL *const rc = &cpi->rc;
+  const PRIMARY_RATE_CONTROL *const p_rc = &cpi->ppi->p_rc;
+#if CONFIG_FPMT_TEST
+  const int simulate_parallel_frame =
+      cpi->ppi->gf_group.frame_parallel_level[cpi->gf_frame_index] > 0 &&
+      cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE;
+  const int avg_inter_qindex = simulate_parallel_frame
+                                   ? p_rc->temp_avg_frame_qindex[INTER_FRAME]
+                                   : p_rc->avg_frame_qindex[INTER_FRAME];
+#else
+  const int avg_inter_qindex = p_rc->avg_frame_qindex[INTER_FRAME];
+#endif
+  int q =
+      (rc->frames_since_key > 1 && avg_inter_qindex < rc->active_worst_quality)
+          ? avg_inter_qindex
+          : rc->active_worst_quality;
+  if (rc_cfg->mode == AOM_CQ && q < rc_cfg->cq_level) q = rc_cfg->cq_level;
+  return q;
+}
+
 static void set_good_speed_feature_framesize_dependent(
     const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
   const AV1_COMMON *const cm = &cpi->common;
@@ -892,12 +917,16 @@ static void set_good_speed_feature_framesize_dependent(
   }

   if (speed >= 3) {
+    const int low_q = get_mode_q_level(cpi) <= 80;
+    const int is_top_pyr =
+        boosted || cpi->ppi->gf_group.layer_depth[cpi->gf_frame_index] <= 2;
     sf->inter_sf.enable_fast_wedge_mask_search = 1;
     sf->inter_sf.skip_newmv_in_drl = 4;
     sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
     sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 3 : 0;
     sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
-    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 1;
+    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning =
+        (low_q && !boosted) ? 2 : 1;
     sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch =
         frame_is_intra_only(&cpi->common) ? 0 : 1;

@@ -914,42 +943,58 @@ static void set_good_speed_feature_framesize_dependent(
     sf->part_sf.ml_4_partition_search_level_index = 3;

     if (is_720p_or_larger) {
-      sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
+      sf->part_sf.partition_search_breakout_dist_thr =
+          (low_q && !boosted) ? (1 << 26) : (1 << 25);
       sf->part_sf.partition_search_breakout_rate_thr = 200;
-      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 2 : 0;
+      sf->part_sf.skip_non_sq_part_based_on_none =
+          (is_lf_frame || (low_q && !is_top_pyr)) ? 2 : 0;
     } else {
       sf->part_sf.max_intra_bsize = BLOCK_32X32;
-      sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
+      sf->part_sf.partition_search_breakout_dist_thr =
+          (low_q && !boosted) ? (1 << 24) : (1 << 23);
       sf->part_sf.partition_search_breakout_rate_thr = 120;
-      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 1 : 0;
+      sf->part_sf.skip_non_sq_part_based_on_none =
+          (is_lf_frame || (low_q && !is_top_pyr)) ? 1 : 0;
     }
     if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;

     if (is_480p_or_larger) {
       sf->part_sf.early_term_after_none_split = 1;
+      if (low_q && !boosted)
+        sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
     } else {
       sf->part_sf.early_term_after_none_split = 0;
     }
     if (is_720p_or_larger) {
-      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 2;
+      sf->intra_sf.skip_intra_in_interframe =
+          boosted ? 1 : ((is_lf_frame || low_q) ? 4 : 2);
     } else {
-      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 3;
+      sf->intra_sf.skip_intra_in_interframe =
+          boosted ? 1 : ((is_lf_frame || low_q) ? 4 : 3);
     }

     if (is_720p_or_larger) {
-      sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
+      sf->inter_sf.disable_interinter_wedge_var_thresh =
+          (is_lf_frame || (low_q && !boosted)) ? UINT_MAX : 100;
       sf->inter_sf.skip_interinter_wedge_search_based_on_mse = 1;
-      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 1;
+      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : (low_q ? 2 : 1);
+      if (low_q) {
+        sf->lpf_sf.cdef_pick_method =
+            is_lf_frame ? CDEF_FAST_SEARCH_LVL3 : CDEF_FAST_SEARCH_LVL1;
+      }
     } else {
       sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
       sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
       sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL2;
     }
+    if (is_lf_frame || (low_q && !boosted))
+      sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;

     if (is_480p_or_lesser) {
       sf->inter_sf.prune_comp_ref_frames = 0;
     } else {
-      sf->inter_sf.prune_comp_ref_frames = 1;
+      sf->inter_sf.prune_comp_ref_frames =
+          (is_lf_frame || (low_q && !is_top_pyr)) ? 2 : 1;
     }

     sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
@@ -959,7 +1004,7 @@ static void set_good_speed_feature_framesize_dependent(
     const int is_top_pyr =
         boosted || (cpi->ppi->gf_group.max_layer_depth >= 6 &&
                     cpi->ppi->gf_group.layer_depth[cpi->gf_frame_index] <= 2);
-    const int high_q = cpi->oxcf.rc_cfg.cq_level > 145;
+    const int high_q = get_mode_q_level(cpi) > 145;
     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning =
         (speed >= 5 || !boosted || !high_q) ? 2 : 1;
     sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
@@ -1107,6 +1152,14 @@ static void set_good_speed_feature_framesize_dependent(
     sf->hl_sf.recode_tolerance = 55;
   }

+  // Relax intra mode pruning on keyframes and ARFs when firstpass identified
+  // the KF group as static screen content.
+  if (speed >= 3 && cpi->ppi->twopass.is_static_sc_kf_group &&
+      (frame_is_intra_only(cm) ||
+       cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == ARF_UPDATE)) {
+    sf->intra_sf.skip_intra_in_interframe = 0;
+  }
+
   if (cpi->oxcf.enable_low_complexity_decode)
     set_good_speed_features_lc_dec_framesize_dependent(cpi, sf, speed);

@@ -1148,6 +1201,8 @@ static void set_good_speed_features_framesize_independent(
   sf->part_sf.simple_motion_search_prune_agg =
       allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL0;

+  sf->mv_sf.reduce_search_range_using_tpl = 1;
+
   sf->inter_sf.inter_mode_rd_model_estimation =
       cpi->oxcf.algo_cfg.sharpness ? 0 : 1;
   sf->inter_sf.model_based_post_interp_filter_breakout = 1;
@@ -1338,31 +1393,66 @@ static void set_good_speed_features_framesize_independent(
   }

   if (speed >= 3) {
+    // Prune partition, motion, transform, and loop-filter searches more
+    // aggressively on non-reference leaf frames and low-quantizer encodes
+    // while preserving search accuracy on top-pyramid reference frames.
+    const int is_lf_frame =
+        gf_group->update_type[cpi->gf_frame_index] == LF_UPDATE;
+    const int is_deep_lf_frame = is_lf_frame && gf_group->max_layer_depth >= 5;
+    const int low_q = get_mode_q_level(cpi) <= 80;
+    const int is_top_pyr =
+        boosted || gf_group->layer_depth[cpi->gf_frame_index] <= 2;
+    sf->hl_sf.disable_extra_sc_testing = 2;
     sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
 #if CONFIG_PYRAMID_ME
     sf->pme_sf.enable_zero_mv_sad = true;
     sf->pme_sf.zero_mv_sad_safe_lmt_thresh = 60000;
     sf->pme_sf.early_exit_thresh = 64 * 64 * 8;
 #endif  // CONFIG_PYRAMID_ME
-    sf->hl_sf.weight_calc_level_in_tf = 1;
+    sf->hl_sf.weight_calc_level_in_tf = low_q ? 0 : 1;
+    sf->hl_sf.tf_subpel_search_method = SUBPEL_TREE_PRUNED;

     sf->gm_sf.prune_ref_frame_for_gm_search = 1;
-    sf->gm_sf.prune_zero_mv_with_sse = 1;
+    sf->gm_sf.prune_zero_mv_with_sse = (is_lf_frame || low_q) ? 2 : 1;
     sf->gm_sf.num_refinement_steps = 0;

     sf->part_sf.simple_motion_search_prune_agg =
         allow_screen_content_tools
             ? SIMPLE_AGG_LVL0
-            : (boosted ? SIMPLE_AGG_LVL3 : QIDX_BASED_AGG_LVL1);
-    sf->part_sf.prune_ext_part_using_split_info = 1;
+            : (boosted ? SIMPLE_AGG_LVL3
+                       : (low_q ? SIMPLE_AGG_LVL4 : QIDX_BASED_AGG_LVL1));
+    sf->part_sf.simple_motion_search_reduce_search_steps =
+        (low_q && !boosted) ? 4 : 0;
+    sf->part_sf.prune_ext_part_using_split_info =
+        (is_lf_frame || (low_q && !boosted)) ? 2 : 1;
     sf->part_sf.simple_motion_search_rect_split = 1;
     sf->part_sf.prune_h_or_v_4part_using_sms_info = true;
+    sf->part_sf.reuse_sms_split_features_for_rect = is_lf_frame != 0;
+    if (low_q && !boosted) {
+      sf->part_sf.ml_predict_breakout_level = 3;
+      sf->part_sf.prune_rectangular_split_based_on_qidx =
+          (allow_screen_content_tools || frame_is_intra_only(&cpi->common))
+              ? 0
+              : (is_lf_frame ? 2 : 1);
+      if (is_lf_frame) {
+        sf->part_sf.prune_sub_8x8_partition_level =
+            allow_screen_content_tools ? 1 : 2;
+      }
+    }

-    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
+    sf->mv_sf.subpel_search_method =
+        (low_q && is_lf_frame) ? SUBPEL_TREE_PRUNED_MORE : SUBPEL_TREE_PRUNED;
+    sf->mv_sf.simple_motion_subpel_force_stop =
+        (is_deep_lf_frame || (low_q && is_lf_frame)) ? HALF_PEL : QUARTER_PEL;
     sf->mv_sf.search_method = DIAMOND;
     sf->mv_sf.disable_second_mv = 2;
     sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_1;
+    sf->mv_sf.reduce_search_range_using_tpl = is_lf_frame ? 2 : 1;
     sf->mv_sf.use_intrabc = 0;
+    if (is_lf_frame || low_q) {
+      sf->mv_sf.warp_search_method = WARP_SEARCH_DIAMOND;
+      sf->mv_sf.warp_search_iters = is_top_pyr ? 4 : 2;
+    }

     sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
     sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
@@ -1371,17 +1461,36 @@ static void set_good_speed_features_framesize_independent(
     // TODO(any): Experiment with the early exit mechanism for speeds 0, 1 and 2
     // and clean-up the speed feature
     sf->inter_sf.perform_best_rd_based_gating_for_chroma = 1;
-    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 2;
+    sf->inter_sf.prune_inter_modes_based_on_tpl =
+        boosted ? 1 : ((low_q && !is_top_pyr) ? 3 : 2);
     sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 2;
     sf->inter_sf.selective_ref_frame = 5;
     sf->inter_sf.retain_last2_in_partial_high_motion = 1;
     sf->inter_sf.reuse_compound_type_decision = 1;
-    set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level,
-                           boosted ? 0 : (is_boosted_arf2_bwd_type ? 1 : 2));
+    if (is_lf_frame || (low_q && !boosted)) {
+      sf->inter_sf.alt_ref_search_fp = 2;
+      sf->inter_sf.prune_ext_comp_using_neighbors = 2;
+      sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
+      sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
+    }
+    if (low_q && !is_top_pyr) {
+      sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_DEFAULT] = 3;
+      sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_MOTION_MODE] = 5;
+      sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = 3;
+    } else {
+      set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level,
+                             boosted ? 0 : (is_boosted_arf2_bwd_type ? 1 : 2));
+    }
     sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 2;
     sf->inter_sf.prune_single_ref = 2;

     sf->interp_sf.adaptive_interp_filter_search = 2;
+    if (low_q && !boosted) {
+      sf->interp_sf.cb_pred_filter_search = 1;
+      if (!is_top_pyr) sf->interp_sf.skip_sharp_interp_filter_search = 1;
+      sf->interp_sf.use_interp_filter = 2;
+      sf->interp_sf.use_more_sharp_interp = 0;
+    }

     // TODO(chiyotsai@google.com): the thresholds chosen for intra hog are
     // inherited directly from luma hog with some minor tweaking. Eventually we
@@ -1396,10 +1505,18 @@ static void set_good_speed_features_framesize_independent(
     sf->tpl_sf.prune_intra_modes = 1;
     sf->tpl_sf.reduce_first_step_size = 6;
     sf->tpl_sf.subpel_force_stop = QUARTER_PEL;
+    sf->tpl_sf.subpel_search_method = SUBPEL_TREE_PRUNED;

     sf->tx_sf.adaptive_txb_search_level = boosted ? 2 : 3;
     sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
     sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
+    if (is_lf_frame || (low_q && !boosted))
+      sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
+
+    if (low_q && !is_top_pyr) {
+      if (is_lf_frame) sf->rd_sf.perform_coeff_opt = 5;
+      sf->winner_mode_sf.dc_blk_pred_level = 2;
+    }

     // TODO(any): Refactor the code related to following winner mode speed
     // features
@@ -1418,14 +1535,26 @@ static void set_good_speed_features_framesize_independent(
     sf->lpf_sf.use_coarse_filter_level_search =
         frame_is_intra_only(&cpi->common) ? 0 : 1;
     sf->lpf_sf.use_downsampled_wiener_stats = 1;
+    if (is_lf_frame || (low_q && !boosted))
+      sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
+
+    // Re-enable IntraBC and relax palette pruning on keyframes and ARFs when
+    // firstpass identified the KF group as static screen content.
+    if (cpi->ppi->twopass.is_static_sc_kf_group &&
+        (frame_is_intra_only(&cpi->common) ||
+         gf_group->update_type[cpi->gf_frame_index] == ARF_UPDATE)) {
+      sf->mv_sf.use_intrabc = 1;
+      sf->intra_sf.prune_palette_search_level = 1;
+    }
   }

   if (speed >= 4) {
-    sf->hl_sf.disable_extra_sc_testing = 1;
 #if CONFIG_PYRAMID_ME
     sf->pme_sf.enable_pyramid_me = false;
 #endif  // CONFIG_PYRAMID_ME
+    sf->hl_sf.tf_subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
     sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
+    sf->tpl_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;

     sf->gm_sf.prune_zero_mv_with_sse = 2;
     sf->gm_sf.downsample_level = 1;
@@ -1436,8 +1565,9 @@ static void set_good_speed_features_framesize_independent(
     sf->part_sf.prune_ext_part_using_split_info = 2;
     sf->part_sf.ml_predict_breakout_level = 3;
     sf->part_sf.prune_rectangular_split_based_on_qidx =
-        (allow_screen_content_tools || frame_is_intra_only(&cpi->common)) ? 0
-                                                                          : 1;
+        (allow_screen_content_tools || frame_is_intra_only(&cpi->common))
+            ? 0
+            : AOMMAX(sf->part_sf.prune_rectangular_split_based_on_qidx, 1);

     sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
     sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
@@ -1456,7 +1586,7 @@ static void set_good_speed_features_framesize_independent(
     // sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC_H_V;
     sf->intra_sf.skip_intra_in_interframe = 4;

-    const int high_q = cpi->oxcf.rc_cfg.cq_level > 145;
+    const int high_q = get_mode_q_level(cpi) > 145;
     sf->tx_sf.tx_type_search.fast_intra_tx_type_search =
         (speed >= 5 || !boosted || !high_q) ? 1 : 0;

@@ -1576,7 +1706,6 @@ static void set_good_speed_features_framesize_independent(
   }

   if (speed >= 6) {
-    sf->hl_sf.disable_extra_sc_testing = 2;
     sf->hl_sf.second_alt_ref_filtering = 0;

     sf->gm_sf.downsample_level = 2;
@@ -2361,6 +2490,7 @@ static inline void init_hl_sf(HIGH_LEVEL_SPEED_FEATURES *hl_sf) {
   hl_sf->ref_frame_mvs_lvl = 0;
   hl_sf->screen_detection_mode2_fast_detection = 0;
   hl_sf->weighted_chroma_distortion = 0;
+  hl_sf->tf_subpel_search_method = SUBPEL_TREE;
 }

 static inline void init_fp_sf(FIRST_PASS_SPEED_FEATURES *fp_sf) {
@@ -2377,6 +2507,7 @@ static inline void init_tpl_sf(TPL_SPEED_FEATURES *tpl_sf) {
   tpl_sf->reduce_first_step_size = 0;
   tpl_sf->skip_alike_starting_mv = 0;
   tpl_sf->subpel_force_stop = EIGHTH_PEL;
+  tpl_sf->subpel_search_method = SUBPEL_TREE;
   tpl_sf->search_method = NSTEP;
   tpl_sf->prune_ref_frames_in_tpl = 0;
   tpl_sf->allow_compound_pred = 1;
@@ -2494,6 +2625,7 @@ static inline void init_part_sf(PARTITION_SPEED_FEATURES *part_sf) {
   part_sf->disable_8x8_part_based_on_qidx = 0;
   part_sf->split_partition_penalty_level = 0;
   part_sf->prune_h_or_v_4part_using_sms_info = false;
+  part_sf->reuse_sms_split_features_for_rect = false;
 }

 static inline void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
@@ -2503,6 +2635,7 @@ static inline void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
   mv_sf->obmc_full_pixel_search_level = 0;
   mv_sf->prune_mesh_search = PRUNE_MESH_SEARCH_DISABLED;
   mv_sf->reduce_search_range = 0;
+  mv_sf->reduce_search_range_using_tpl = 0;
   mv_sf->search_method = NSTEP;
   mv_sf->simple_motion_subpel_force_stop = EIGHTH_PEL;
   mv_sf->subpel_force_stop = EIGHTH_PEL;
@@ -2642,7 +2775,7 @@ static inline void init_tx_sf(TX_SPEED_FEATURES *tx_sf) {
   tx_sf->prune_intra_tx_depths_using_nn = false;
   tx_sf->use_rd_based_breakout_for_intra_tx_search = false;
   tx_sf->prune_inter_tx_split_rd_eval_lvl = 0;
-  tx_sf->use_chroma_trellis_rd_mult = 0;
+  tx_sf->use_chroma_trellis_rd_mult = 1;
 }

 static inline void init_rd_sf(RD_CALC_SPEED_FEATURES *rd_sf,
@@ -2806,21 +2939,27 @@ static fractional_mv_step_fp *const
       av1_find_best_sub_pixel_tree_pruned_more  // SUBPEL_TREE_PRUNED_MORE = 2
     };

-// Populate appropriate sub-pel search method based on speed feature and user
-// specified settings
-static void set_subpel_search_method(
-    MotionVectorSearchParams *mv_search_params,
+static fractional_mv_step_fp *get_subpel_search_method(
     unsigned int motion_vector_unit_test,
     SUBPEL_SEARCH_METHOD subpel_search_method) {
   assert(subpel_search_method <= SUBPEL_TREE_PRUNED_MORE);
-  mv_search_params->find_fractional_mv_step =
-      fractional_mv_search[subpel_search_method];
-
   // This is only used in motion vector unit test.
-  if (motion_vector_unit_test == 1)
-    mv_search_params->find_fractional_mv_step = av1_return_max_sub_pixel_mv;
-  else if (motion_vector_unit_test == 2)
-    mv_search_params->find_fractional_mv_step = av1_return_min_sub_pixel_mv;
+  if (motion_vector_unit_test == 1) return av1_return_max_sub_pixel_mv;
+  if (motion_vector_unit_test == 2) return av1_return_min_sub_pixel_mv;
+  return fractional_mv_search[subpel_search_method];
+}
+
+// Populate appropriate sub-pel search method based on speed feature and user
+// specified settings
+static void set_subpel_search_method(MotionVectorSearchParams *mv_search_params,
+                                     unsigned int motion_vector_unit_test,
+                                     const SPEED_FEATURES *sf) {
+  mv_search_params->find_fractional_mv_step = get_subpel_search_method(
+      motion_vector_unit_test, sf->mv_sf.subpel_search_method);
+  mv_search_params->find_fractional_mv_step_tpl = get_subpel_search_method(
+      motion_vector_unit_test, sf->tpl_sf.subpel_search_method);
+  mv_search_params->find_fractional_mv_step_tf = get_subpel_search_method(
+      motion_vector_unit_test, sf->hl_sf.tf_subpel_search_method);
 }

 void av1_set_speed_features_framesize_dependent(AV1_COMP *cpi, int speed) {
@@ -2847,8 +2986,7 @@ void av1_set_speed_features_framesize_dependent(AV1_COMP *cpi, int speed) {
   }

   set_subpel_search_method(&cpi->mv_search_params,
-                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
-                           sf->mv_sf.subpel_search_method);
+                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test, sf);

   // For multi-thread use case with row_mt enabled, cost update for a set of
   // SB rows is not desirable. Hence, the sf mv_cost_upd_level is set to
@@ -2962,8 +3100,7 @@ void av1_set_speed_features_framesize_independent(AV1_COMP *cpi, int speed) {
     sf->hl_sf.recode_loop = DISALLOW_RECODE;

   set_subpel_search_method(&cpi->mv_search_params,
-                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
-                           sf->mv_sf.subpel_search_method);
+                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test, sf);

   // assert ensures that tx_domain_dist_level is accessed correctly
   assert(cpi->sf.rd_sf.tx_domain_dist_thres_level >= 0 &&
@@ -3206,9 +3343,22 @@ void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
     sf->part_sf.less_rectangular_check_level = 1;
   }

-  if (speed == 3)
+  if (speed == 3) {
+    // Relax rectangular partition pruning on boosted reference frames.
     sf->part_sf.less_rectangular_check_level =
-        (cm->quant_params.base_qindex >= 170) ? 1 : 2;
+        (boosted || cm->quant_params.base_qindex >= 170) ? 1 : 2;
+    // Skip SGR and Wiener tap refinement on non-boosted frames at extreme
+    // quantizers while keeping single-shot Wiener restoration active.
+    if (!boosted && !is_arf2_bwd_type) {
+      const int qindex_low[2] = { 100, 60 };
+      const int qindex_high[2] = { 180, 160 };
+      if (cm->quant_params.base_qindex <= qindex_low[is_720p_or_larger] ||
+          cm->quant_params.base_qindex > qindex_high[is_720p_or_larger]) {
+        sf->lpf_sf.disable_sgr_filter = true;
+        sf->lpf_sf.disable_wiener_coeff_refine_search = true;
+      }
+    }
+  }

   if (speed >= 4) {
     // Disable LR search at low and high quantizers and enable only for
@@ -3217,7 +3367,7 @@ void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
       const int qindex_low[2] = { 100, 60 };
       const int qindex_high[2] = { 180, 160 };
       if (cm->quant_params.base_qindex <= qindex_low[is_720p_or_larger] ||
-          cm->quant_params.base_qindex > qindex_high[is_720p_or_larger]) {
+          cm->quant_params.base_qindex >= qindex_high[is_720p_or_larger]) {
         sf->lpf_sf.disable_sgr_filter = true;
         sf->lpf_sf.disable_wiener_coeff_refine_search = true;
       }
@@ -3294,8 +3444,7 @@ void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
   }

   set_subpel_search_method(&cpi->mv_search_params,
-                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
-                           sf->mv_sf.subpel_search_method);
+                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test, sf);

   // Apply faster motion search and downsampled SAD for GOOD mode at speed > 2.
   const int is_lf_frame =
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index d4cccd74d3..e136f69b1c 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -493,6 +493,11 @@ typedef struct HIGH_LEVEL_SPEED_FEATURES {
    */
   int allow_sub_blk_me_in_tf;

+  /*!
+   * Sub-pixel search method used in temporal filtering motion estimation.
+   */
+  SUBPEL_SEARCH_METHOD tf_subpel_search_method;
+
   /*!
    * Decide whether to disable temporal mv prediction.
    * 0: Do not disable
@@ -570,6 +575,9 @@ typedef struct TPL_SPEED_FEATURES {
   // When to stop subpel search.
   SUBPEL_FORCE_STOP subpel_force_stop;

+  // Sub-pixel search method used in TPL motion estimation.
+  SUBPEL_SEARCH_METHOD subpel_search_method;
+
   // Which search method to use.
   SEARCH_METHODS search_method;

@@ -958,6 +966,10 @@ typedef struct PARTITION_SPEED_FEATURES {
   // simple motion search.
   bool prune_h_or_v_4part_using_sms_info;

+  // Reuse simple motion search split features for rectangular partition
+  // pruning instead of running separate rectangular simple motion searches.
+  bool reuse_sms_split_features_for_rect;
+
   // Decoder side speed feature to add penalty for use of smaller partitions.
   // Takes values 0 - 2, 0 indicating no penalty and higher level indicating
   // increased penalty.
@@ -1011,6 +1023,13 @@ typedef struct MV_SPEED_FEATURES {
   // Reduce single motion search range based on MV result of prior ref_mv_idx.
   int reduce_search_range;

+  // Reduce motion search range when TPL MVs agree across the block.
+  // 0: disabled
+  // 1: reduce single motion search range when TPL MVs agree unanimously
+  // 2: reduce single motion search range when >75% of TPL MVs agree, and
+  //    reduce simple motion search range when TPL MVs agree unanimously
+  int reduce_search_range_using_tpl;
+
   // Prune mesh search.
   PRUNE_MESH_SEARCH_LEVEL prune_mesh_search;

diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 9498caf14d..6ec8c04a0c 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -124,7 +124,7 @@ static void subblock_motion_search(

   MV subpel_start_mv = get_mv_from_fullmv(&best_mv.as_fullmv);
   assert(av1_is_subpelmv_in_range(&ms_params->mv_limits, subpel_start_mv));
-  error = cpi->mv_search_params.find_fractional_mv_step(
+  error = cpi->mv_search_params.find_fractional_mv_step_tf(
       &mb->e_mbd, &cpi->common, ms_params, subpel_start_mv, best_mv_stats,
       &best_mv.as_mv, &distortion, &sse, NULL);

@@ -373,7 +373,7 @@ static void tf_motion_search(AV1_COMP *cpi, MACROBLOCK *mb,

     MV subpel_start_mv = get_mv_from_fullmv(&best_mv.as_fullmv);
     assert(av1_is_subpelmv_in_range(&ms_params.mv_limits, subpel_start_mv));
-    error = cpi->mv_search_params.find_fractional_mv_step(
+    error = cpi->mv_search_params.find_fractional_mv_step_tf(
         &mb->e_mbd, &cpi->common, &ms_params, subpel_start_mv, &best_mv_stats,
         &best_mv.as_mv, &distortion, &sse, NULL);
     block_mse = DIVIDE_AND_ROUND(error, mb_pels);
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 94f4771d57..1116271da1 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -340,7 +340,7 @@ static uint32_t motion_estimation(AV1_COMP *cpi, MACROBLOCK *x,
   best_mv_stats.err_cost = 0;
   MV subpel_start_mv = get_mv_from_fullmv(&best_mv->as_fullmv);
   assert(av1_is_subpelmv_in_range(&ms_params.mv_limits, subpel_start_mv));
-  bestsme = cpi->mv_search_params.find_fractional_mv_step(
+  bestsme = cpi->mv_search_params.find_fractional_mv_step_tpl(
       xd, cm, &ms_params, subpel_start_mv, &best_mv_stats, &best_mv->as_mv,
       &distortion, &sse, NULL);

@@ -503,7 +503,17 @@ static inline int32_t get_inter_cost(const AV1_COMP *cpi, MACROBLOCKD *xd,
   const int bh = 4 << mi_size_high_log2[bsize];
   int32_t inter_cost;

-  if (cpi->sf.tpl_sf.subpel_force_stop != FULL_PEL) {
+  // Only invoke 8-tap subpel interpolation when the MV has fractional
+  // components or crosses the reference frame border; otherwise read directly
+  // from the reference buffer.
+  const int is_subpel = ((rfidx_mv->row | rfidx_mv->col) & 7) != 0;
+  const int full_row = mi_row * MI_SIZE + (rfidx_mv->row >> 3);
+  const int full_col = mi_col * MI_SIZE + (rfidx_mv->col >> 3);
+  const int is_out_of_bounds = full_row < 0 || full_col < 0 ||
+                               full_row + bh > ref_frame_ptr->y_height ||
+                               full_col + bw > ref_frame_ptr->y_width;
+  if (cpi->sf.tpl_sf.subpel_force_stop != FULL_PEL &&
+      (is_subpel || is_out_of_bounds)) {
     const int_interpfilters kernel =
         av1_broadcast_interp_filter(EIGHTTAP_REGULAR);
     uint8_t *predictor8 = tpl_tmp_buffers->predictor8;
@@ -2180,7 +2190,7 @@ int av1_tpl_setup_stats(AV1_COMP *cpi, int approx_gop_eval,
                     cm->features.allow_high_precision_mv, cpi->td.mb.mv_costs);

   const TPL_SPEED_FEATURES saved_tpl_sf = cpi->sf.tpl_sf;
-  if (cpi->oxcf.speed == 4) {
+  if (cpi->oxcf.mode == GOOD && cpi->oxcf.speed == 4) {
     if (approx_gop_eval) {
       // Use faster half-pel diamond search during approximate GOP length
       // evaluation, and restrict RD to luma unless keyframe stats indicate