Skip to content

building long strings through concatenation is quadratic in complexity #50304

Open
@bksubhuti

Description

@bksubhuti

I have a dictionary with 200,000 records.
Normally I process these records in js and I can read and write an 18MB file within a few seconds. (Note:.. older file about 168,000).

However, when I tried doing this in Dart for our re-written product, I ran into problems with .fromJson parsing. There seemed to be a limit of less than 90,000.

Further investigation had me try processing a csv manually.
Further investigation had me write a csv manually in case my data was bad.
Further investigation had me write a dart cli ...

The code is shown below and takes roughly 1 second per 1000 merely to do string processing in memory.
The flutter code of the same thing takes about 2.5 seconds per 1000.
So in flutter (for my real life dictionary import feature), we are talking about 600 seconds or 10 minutes. I have not ran any of these scripts to completion. They appear as "hung" even though they are just taking a long time.

Meanwhile.. I can read an sql file and pass db.Update(sql); in a few seconds.
For now, I will need to store my data online for downloading dictionary updates as Raw SQL transaction inserts.

I never thought I would report speed as a bug. But when we are talking a few seconds in js versus 10 minutes, this appears as "hung" and counts as a bug. I love dart flutter, but had I known about this limitation, I might have opted for something else. on the other hand the framework and using db's does not require us to feel this pain until now.

Hardware: Lenovo IdeaPad 3 14ALC6
Ubuntu 22.04.1
[✓] Flutter (Channel stable, 3.3.5, on Ubuntu 22.04.1 LTS 5.15.0-52-generic, locale en_US.UTF-8)

$ flutter --version
Flutter 3.3.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d9111f6402 (6 days ago) • 2022-10-19 12:27:13 -0700
Engine • revision 3ad69d7be3
Tools • Dart 2.18.2 • DevTools 2.15.0

import 'package:cli/cli.dart' as cli;
import 'dart:core';
void main(List<String> arguments) {
  //print('Hello world: ${cli.calculate()}!');

  String myString = "";
  // make 200k records
  for (int x = 0; x < 200000; x++) {
    myString += "$x, another variable$x, 8\n";
    if (x % 1000 == 1) {
      print("$x");
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-documentationPrefer using 'type-documentation' and a specific area label.type-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions