Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Huge memory consumption #76

Open
1 task done
EArminjon opened this issue Aug 31, 2022 · 11 comments
Open
1 task done

fix: Huge memory consumption #76

EArminjon opened this issue Aug 31, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@EArminjon
Copy link

EArminjon commented Aug 31, 2022

Is there an existing issue for this?

  • I have searched the existing issues.

Version

0.4.1

Description

Our app have many, many golden test like following. The issue is about memory consumption, we are today at 40go every run. Do you know what in golden test took so much memory ? Any general good practice ?

 goldenTest(
      'renders texts correctly',
      fileName:
          'theme-texts-${flavor.runtimeType.toString().toLowerCase()}-${mode.name}',
      builder: () => GoldenTestGroup(
        columns: 1,
        children: <GoldenTestScenario>[
          GoldenTestScenario(
            name: 'body text 1',
            child: Text(
              'Sample text',
              style: textTheme.bodyText1,
            ),
          ),
          GoldenTestScenario(
            name: 'body text 2',
            child: Text(
              'Sample text',
              style: textTheme.bodyText2,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 1',
            child: Text(
              'Sample text',
              style: textTheme.headline1,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 2',
            child: Text(
              'Sample text',
              style: textTheme.headline2,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 3',
            child: Text(
              'Sample text',
              style: textTheme.headline3,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 4',
            child: Text(
              'Sample text',
              style: textTheme.headline4,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 5',
            child: Text(
              'Sample text',
              style: textTheme.headline5,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 6',
            child: Text(
              'Sample text',
              style: textTheme.headline6,
            ),
          ),
          GoldenTestScenario(
            name: 'subtitle 1',
            child: Text(
              'Sample text',
              style: textTheme.subtitle1,
            ),
          ),
          GoldenTestScenario(
            name: 'subtitle 2',
            child: Text(
              'Sample text',
              style: textTheme.subtitle2,
            ),
          ),
        ],
      ),
    );

Capture d’écran 2022-08-31 à 15 54 02

Steps to reproduce

run many golden test

Expected behavior

As less memory as possible

Screenshots

No response

Additional context and comments

No response

@EArminjon EArminjon added the bug Something isn't working label Aug 31, 2022
@Kirpal
Copy link
Collaborator

Kirpal commented Aug 31, 2022

Does this happen when you run the provided example or when you run all the tests in your app at once? I'm unable to reproduce using the example.

@EArminjon
Copy link
Author

EArminjon commented Aug 31, 2022

Does this happen when you run the provided example or when you run all the tests in your app at once? I'm unable to reproduce using the example.

Will try tomorrow. We have 104 golden test and would increase a lot the number...

@EArminjon
Copy link
Author

EArminjon commented Sep 4, 2022

Example consume few giga when copy paste >100 test but not 40g. I need to find where in our app we have the issue. @Kirpal , Is their any practice to absolutely avoid when doing golden test ? Must i cache something ?

@EArminjon
Copy link
Author

EArminjon commented Sep 7, 2022

@Kirpal this example use 10go (in our app we used 3 other similar process which increase the total near 40go)
The goal of this test which i simplified is to run many golden test for Light and Dark theme for each Flavor of our app. I remove here the flavor logic and just use a simple List.generate to mimic.

import 'package:alchemist/alchemist.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';

final List<ThemeMode> modes = <ThemeMode>[ThemeMode.light, ThemeMode.dark];

void goldenForAllThemesAndModes(
  void Function(
    dynamic flavorConfig,
    ThemeMode themeMode,
    ThemeData themeData,
  )
      run,
) {
  for (final int index in List<int>.generate(13, (int index) => index)) {
    for (final ThemeMode mode in modes) {
      final ThemeData themeData =
          mode == ThemeMode.light ? ThemeData.light() : ThemeData.dark();
      AlchemistConfig.runWithConfig(
        config: AlchemistConfig(theme: themeData),
        run: () => run(index, mode, themeData),
      );
    }
  }
}

void main() {
  setUpAll(() async {
    await loadAppFonts();
  });

  void _textsTest(
    dynamic abstractConfig,
    ThemeMode mode,
    TextTheme textTheme,
  ) {
    goldenTest(
      'renders texts correctly',
      fileName:
          'theme-texts-${abstractConfig.toString().toLowerCase()}-${mode.name}',
      builder: () => GoldenTestGroup(
        columns: 1,
        children: <GoldenTestScenario>[
          GoldenTestScenario(
            name: 'body text 1',
            child: Text(
              'Sample text',
              style: textTheme.bodyText1,
            ),
          ),
          GoldenTestScenario(
            name: 'body text 2',
            child: Text(
              'Sample text',
              style: textTheme.bodyText2,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 1',
            child: Text(
              'Sample text',
              style: textTheme.headline1,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 2',
            child: Text(
              'Sample text',
              style: textTheme.headline2,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 3',
            child: Text(
              'Sample text',
              style: textTheme.headline3,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 4',
            child: Text(
              'Sample text',
              style: textTheme.headline4,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 5',
            child: Text(
              'Sample text',
              style: textTheme.headline5,
            ),
          ),
          GoldenTestScenario(
            name: 'headline 6',
            child: Text(
              'Sample text',
              style: textTheme.headline6,
            ),
          ),
          GoldenTestScenario(
            name: 'subtitle 1',
            child: Text(
              'Sample text',
              style: textTheme.subtitle1,
            ),
          ),
          GoldenTestScenario(
            name: 'subtitle 2',
            child: Text(
              'Sample text',
              style: textTheme.subtitle2,
            ),
          ),
        ],
      ),
    );
  }

  group('theme', () {
    goldenForAllThemesAndModes(
      (
        dynamic abstractConfig,
        ThemeMode themeMode,
        ThemeData themeData,
      ) {
        _textsTest(abstractConfig, themeMode, themeData.textTheme);
      },
    );
  });
}

@EArminjon
Copy link
Author

hi @Kirpal,

Do you well achieve to reproduce the issue ?

@EArminjon
Copy link
Author

@Kirpal have you got time to check :'( ?

@EArminjon
Copy link
Author

Hi @Kirpal ,

Any update :'( ?

@EArminjon
Copy link
Author

up

@FufferKS
Copy link

I think I'm running into the same issue. My reproducible example below. Raw flutter test does not break a sweat. Alchemist version makes my macbook freeze after a few runs.

`enum HomeGoldenType { raw, alchemist }`

  for (var i = 0; i < 1000; i++) {
    await runTheGolden(i, HomeGoldenType.raw);
  }
  
  Future<void> runTheGolden(int iter, HomeGoldenType type) async {
    final testName = 'Home Iteration $iter';
    final fileName = 'home_iteration_$iter';
    final materialApp = MaterialApp(
      home: Builder(
        builder: (context) => ColoredBox(
          color: type == HomeGoldenType.raw ? Colors.red : Colors.blue,
          child: const Placeholder(),
        ),
      ),
    );
    if (type == HomeGoldenType.raw) {
      testWidgets(
        testName,
        (WidgetTester tester) async {
          debugPrint('running iteration $iter');
          await tester.pumpWidget(materialApp);
          await tester.pumpAndSettle();
          expect(find.byType(MaterialApp), matchesGoldenFile('$fileName.png'));
          debugPrint('finished iteration $iter');
        },
        tags: ['golden-expensiveness'],
      );
    } else if (type == HomeGoldenType.alchemist) {
      await goldenTest(
        testName,
        fileName: fileName,
        pumpBeforeTest: (t) {
          debugPrint('running iteration $iter');
          return t.pump();
        },
        whilePerforming: (tester) async {
          return () async {
            debugPrint('finished iteration $iter');
          };
        },
        constraints: BoxConstraints.tight(kDefaultTestViewport),
        builder: () => materialApp,
        tags: ['golden-expensiveness'],
      );
    }
  }

@EArminjon
Copy link
Author

EArminjon commented Nov 23, 2023

Check on your MacOS activity monitor app your RAM usage, if RAM is high, yep same issue :)

@FufferKS
Copy link

Oh yes it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants