Skip to content

Fast sink doesn't work when using Wasm #250

@h1376h

Description

@h1376h

Sample code:

import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Testing fast sink on Wasm',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const BenchmarkPage(),
    );
  }
}

class BenchmarkPage extends StatefulWidget {
  const BenchmarkPage({super.key});

  @override
  State<BenchmarkPage> createState() => _BenchmarkPageState();
}

class _BenchmarkPageState extends State<BenchmarkPage> {
  String benchmarkResult = '';

  void _runBenchmark() {
    final stopwatch = Stopwatch()..start();
    for (int i = 0; i < 100000; i++) {
      // Create deterministic strings
      String data = "Deterministic string $i";
      var bytes = utf8.encode(data);
      // Compute SHA-512
      sha512.convert(bytes);
    }
    stopwatch.stop();
    setState(() {
      benchmarkResult = 'Time taken: ${stopwatch.elapsedMilliseconds} ms';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: _runBenchmark,
              child: const Text('Run Benchmark'),
            ),
            Text(
              benchmarkResult,
              style: Theme.of(context).textTheme.bodyMedium,
            ),
          ],
        ),
      ),
    );
  }
}

This code works when using slow sinks, but gives errors now (on master) using fast sinks

flutter build web --wasm

cd build/web

dhttpd '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'

The integer literal 0x8c3d37c819544da2 can't be represented exactly in JavaScript.
0x8c3d37c819544da2,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions