Skip to content

Commit

Permalink
Merge pull request #634 from lichess-org/default-engine-cores
Browse files Browse the repository at this point in the history
Set default engine cores as half of nb of processors
  • Loading branch information
veloce authored Apr 15, 2024
2 parents 85b1651 + ebc6ad0 commit 1aedcba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/src/model/analysis/analysis_preferences.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -106,7 +104,7 @@ class AnalysisPrefState with _$AnalysisPrefState {
showBestMoveArrow: true,
showPgnComments: true,
numEvalLines: 2,
numEngineCores: maxEngineCores,
numEngineCores: defaultEngineCores,
);

factory AnalysisPrefState.fromJson(Map<String, dynamic> json) {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/model/engine/evaluation_service.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/src/view/analysis/analysis_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 1aedcba

Please sign in to comment.