From ebc6ad0eaecc9cf0a18e1bca96ba2abf9ba9e9e3 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Mon, 15 Apr 2024 09:19:22 +0200 Subject: [PATCH] Set default engine cores as half of nb of processors --- lib/src/model/analysis/analysis_preferences.dart | 6 ++---- lib/src/model/engine/evaluation_service.dart | 7 +++++-- lib/src/view/analysis/analysis_settings.dart | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/model/analysis/analysis_preferences.dart b/lib/src/model/analysis/analysis_preferences.dart index 621b7ad4cd..45d615baef 100644 --- a/lib/src/model/analysis/analysis_preferences.dart +++ b/lib/src/model/analysis/analysis_preferences.dart @@ -1,15 +1,13 @@ import 'dart:convert'; -import 'dart:io'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/db/shared_preferences.dart'; +import 'package:lichess_mobile/src/model/engine/evaluation_service.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'analysis_preferences.freezed.dart'; part 'analysis_preferences.g.dart'; -final maxEngineCores = Platform.numberOfProcessors - 1; - @Riverpod(keepAlive: true) class AnalysisPreferences extends _$AnalysisPreferences { static const prefKey = 'preferences.analysis'; @@ -106,7 +104,7 @@ class AnalysisPrefState with _$AnalysisPrefState { showBestMoveArrow: true, showPgnComments: true, numEvalLines: 2, - numEngineCores: maxEngineCores, + numEngineCores: defaultEngineCores, ); factory AnalysisPrefState.fromJson(Map json) { diff --git a/lib/src/model/engine/evaluation_service.dart b/lib/src/model/engine/evaluation_service.dart index 206752b04a..95d6e854c2 100644 --- a/lib/src/model/engine/evaluation_service.dart +++ b/lib/src/model/engine/evaluation_service.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:io'; +import 'dart:math'; import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; @@ -19,7 +20,9 @@ part 'evaluation_service.g.dart'; part 'evaluation_service.freezed.dart'; const kMaxEngineDepth = 22; -final maxEngineCores = Platform.numberOfProcessors - 1; +final maxEngineCores = max(Platform.numberOfProcessors - 1, 1); +final defaultEngineCores = + min((Platform.numberOfProcessors / 2).ceil(), maxEngineCores); const engineSupportedVariants = { Variant.standard, @@ -38,7 +41,7 @@ class EvaluationService { EvaluationContext? _context; EvaluationOptions _options = EvaluationOptions( multiPv: 1, - cores: maxEngineCores, + cores: defaultEngineCores, ); /// Initialize the engine with the given context and options. diff --git a/lib/src/view/analysis/analysis_settings.dart b/lib/src/view/analysis/analysis_settings.dart index 53f27a794f..0df8b75992 100644 --- a/lib/src/view/analysis/analysis_settings.dart +++ b/lib/src/view/analysis/analysis_settings.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart'; +import 'package:lichess_mobile/src/model/engine/evaluation_service.dart'; import 'package:lichess_mobile/src/model/settings/general_preferences.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/widgets/adaptive_bottom_sheet.dart';