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

performance nosedives on large writes to OutputStream #834

Closed
DartBot opened this issue Dec 13, 2011 · 6 comments
Closed

performance nosedives on large writes to OutputStream #834

DartBot opened this issue Dec 13, 2011 · 6 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io

Comments

@DartBot
Copy link

DartBot commented Dec 13, 2011

This issue was originally filed by dcarlson@google.com


Large List<int> values cause performance of SocketOutputStream.writeFrom() (and similar) to degrade dramatically. Specific timings are largely platform-dependent, but the overall effect is reproducible across machines/OSes.

The problem can be reproduced with the following code:
<code>
final int LO = 430000;
final int HI = 500000;
final int SIZE = 500000;

final int INC = 1024;

void main() {
  List<int> content = new List();
  content.insertRange(0, SIZE, 0);
  int j = 0;
  for(int i = 0; i < SIZE; i++) {
    content[i] = j;
    j++;
    if(j >= 256) j = 0;
  }
  stderr.write("size\ttime(micros)\ttime/byte\n".charCodes());
  
  for (int i = LO; i < HI; i += INC) {
    Stopwatch s = new Stopwatch();
    s.start();
    stdout.writeFrom(content, 0, i);
    s.stop();
    int time = s.elapsedInUs();
    num time_per_byte = time / i;
    stderr.write("$i\t$time\t$time_per_byte\n".charCodes());
  }
}

</code>

Run this redirecting stdout to /dev/null and it will report performance on stderr. Your exact point of failure may vary, but with the timing output, you can refine the test to demonstrate super-linear performance beyond some threshold.

For example, here is the interesting subset of output where INC is set to 16 (note this is running on Linux using dart HEAD of bleeding_edge as of 12/12/2011):
...
size micro- microsecs/
(bytes) secs byte
461376 322392 0.698762
461392 322330 0.698603
461408 322551 0.699058
461424 322620 0.699183
461440 322526 0.698955
461456 322786 0.699495
461472 322473 0.698792
461488 322711 0.699284
461504 321257 0.696109
461520 840764 1.821728
461536 2511238 5.441045
461552 4184249 9.065607
461568 5856430 12.68812
461584 7523204 16.298667
461600 9197491 19.92524
461616 10865756 23.538517
461632 12543308 27.171661
461648 14214076 30.789857
461664 15890033 34.419043
461680 17560101 38.035221

@DartBot
Copy link
Author

DartBot commented Dec 13, 2011

This comment was originally written by dcarlson@google.com


For clarity, this behavior is being seen in the runtime.

@DartBot
Copy link
Author

DartBot commented Dec 13, 2011

This comment was originally written by dcarlson@google.com


Also -- this performance is observed when the input to the writeFrom method is a GrowableArray.

@whesse
Copy link
Contributor

whesse commented Dec 13, 2011

This may be a GC (garbage collector) issue, and/or we may be creating a large number of objects for some reason. We will look into this.


Set owner to @whesse.

@floitschG
Copy link
Contributor

Removed Area-Library label.
Added Area-IO label.

@sgjesse
Copy link
Contributor

sgjesse commented Feb 27, 2013

With lib IO v2 the test can be rewritten like this:

final int LO = 100000;
final int HI = 5000000;
final int SIZE = 5000000;

final int INC = 100000;

void main() {
  List<int> content = new List(SIZE);
  //content.insertRange(0, SIZE, 0);
  int j = 0;
  for (int i = 0; i < SIZE; i++) {
    content[i] = j;
    j++;
    if (j >= 256) j = 0;
  }
  stderr.addString("size\ttime(micros)\ttime/byte\n");

  x(int size) {
    Stopwatch s = new Stopwatch();
    s.start();
    var controller = new StreamController();
    Future done = stdout.addStream(controller.stream);
    controller.add(content.getRange(0, size));
    controller.close();
    done.then((_) {
      s.stop();
      int time = s.elapsedMicroseconds;
      num time_per_byte = time / size;
      stderr.addString("$size\t$time\t$time_per_byte\n");
      if (size < HI) x(size + INC);
    });
  }
  x(LO);
}

Running the keeps a pretty steady rate for all sizes.


Added Fixed label.

@kevmoo
Copy link
Member

kevmoo commented May 14, 2014

Removed Area-IO label.
Added Area-Library, Library-IO labels.

@DartBot DartBot added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels May 14, 2014
copybara-service bot pushed a commit that referenced this issue May 30, 2023
…buf, shelf, test, tools, vector_math, webdev

Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/59dc475..1d94484):
  1d94484c  2023-05-29  dependabot[bot]  Bump github/codeql-action from 2.3.3 to 2.3.5 (#3422)
  0edc1a71  2023-05-28  dependabot[bot]  Bump http from 0.13.6 to 1.0.0 (#3421)

http (https://github.com/dart-lang/http/compare/dfec389..8a4a4a6):
  8a4a4a6  2023-05-25  Brian Quinlan  Add a better toString to _ClientSocketException (#948)
  5c1f1ad  2023-05-25  Devon Carew  regenerate with the latest mono_repo (#947)

leak_tracker (https://github.com/dart-lang/leak_tracker/compare/9c6e9b3..7f2cab3):
  7f2cab3  2023-05-26  Polina Cherkasova  Nicely format retaining path. (#68)

lints (https://github.com/dart-lang/lints/compare/72f107a..4236c43):
  4236c43  2023-05-26  Parker Lougheed  Remove pedantic from README (#124)
  4ac79d8  2023-05-24  Parker Lougheed  Update example for latest lints version (#123)

mockito (https://github.com/dart-lang/mockito/compare/153c145..40fe2ca):
  40fe2ca  2023-05-25  Nate Bosch  Expand constraint on package:http

native (https://github.com/dart-lang/native/compare/45e16dc..76bc55e):
  76bc55e  2023-05-30  Daco Harkes  [c_compiler] Target ios_x64 (#53)

protobuf (https://github.com/dart-lang/protobuf/compare/7d2d293..346a72d):
  346a72d  2023-05-30  Ömer Sinan Ağacan  Fix generated ignore_for_file directives (#833)
  35ea45f  2023-05-26  Kevin Moore  Latest mono_repo (#834)

shelf (https://github.com/dart-lang/shelf/compare/56919a1..a404b6a):
  a404b6a  2023-05-25  Devon Carew  re-generate w/ the latest monorepo (#362)

test (https://github.com/dart-lang/test/compare/309596e..3276921):
  32769215  2023-05-25  dependabot[bot]  Bump github/codeql-action from 2.3.2 to 2.3.5 (#2023)
  f74e85c8  2023-05-25  dependabot[bot]  Bump dart-lang/setup-dart from 1.3.0 to 1.5.0 (#2022)
  4b2bd272  2023-05-25  Devon Carew  update the mono_repo and dependabot configs (#2021)

tools (https://github.com/dart-lang/tools/compare/81ff996..b90a7e8):
  b90a7e8  2023-05-26  Devon Carew  blast_repo fixes (#106)

vector_math (https://github.com/google/vector_math.dart/compare/e3de8da..cd87f57):
  cd87f57  2023-05-30  JKris95  Axis calculation of quaternions from small angles (#272)
  3762b25  2023-05-30  Lukas Klingsbo  Removes the `new` keyword from readme (#284)
  df5877f  2023-05-30  Lukas Klingsbo  Use named constructors in Vector2 and some general optimizations (#289)

webdev (https://github.com/dart-lang/webdev/compare/d74fadd..4b69f1d):
  4b69f1dd  2023-05-26  Anna Gringauze  fix format breaking tests (#2124)
  b75f8e62  2023-05-25  Devon Carew  re-generate w/ the latest monorepo (#2121)

Change-Id: Ide9b7781102b654db15114d01cd4fbca40478906
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306304
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
copybara-service bot pushed a commit that referenced this issue Dec 1, 2023
…ocess, vector_math, web, webdev

Revisions updated by `dart tools/rev_sdk_deps.dart`.

native (https://github.com/dart-lang/native/compare/0051e78..b5827f3):
  b5827f3b  2023-11-29  Daco Harkes  [infra] Hide TODOs from problems view in VSCode (#837)
  17487159  2023-11-29  Liam Appelbe  [ffigen] Only use `objc_msgSend` variants on x64 (#836)
  50b6a783  2023-11-28  Ryan Macnak  [native_toolchain_c] Setup Android RISCV64 toolchain. (#165)
  aa58de61  2023-11-28  Daco Harkes  [native] Bump deps (#834)
  6cf4c783  2023-11-28  Daco Harkes  [native_assets_builder] Only build native assets for dependencies of requested package (#833)
  f1221814  2023-11-28  Daco Harkes  [ffigen][infra] Use Apple silicon on CI (#832)

source_span (https://github.com/dart-lang/source_span/compare/ed16e0d..9398e24):
  9398e24  2023-11-29  Kevin Moore  Move to latest lints, require Dart 3.1 (#106)

stack_trace (https://github.com/dart-lang/stack_trace/compare/6496ff8..4abff44):
  4abff44  2023-11-29  Kevin Moore  Latest lints, require Dart ^3.1 (#146)

test_descriptor (https://github.com/dart-lang/test_descriptor/compare/c417cbb..59ce97f):
  59ce97f  2023-11-29  Kevin Moore  Bump and fix latest lints, require Dart 3.1 (#60)

test_process (https://github.com/dart-lang/test_process/compare/c21e40d..d68de5b):
  d68de5b  2023-11-29  Kevin Moore  Update lints, require Dart ^3.1 (#52)

vector_math (https://github.com/google/vector_math.dart/compare/e4066cc..cca3cf1):
  cca3cf1  2023-11-27  Devon Carew  Update README.md (#308)

web (https://github.com/dart-lang/web/compare/fdfbaef..cffc2e3):
  cffc2e3  2023-11-30  Devon Carew  parse spec info for generated libraries (#111)
  d902401  2023-11-29  Devon Carew  update the readme (#110)
  e5be5b3  2023-11-28  Devon Carew  delete previously generated files when generating (#108)

webdev (https://github.com/dart-lang/webdev/compare/6961b20..63e09e5):
  63e09e50  2023-11-30  Elliott Brooks  Remove unused scripting code and permission (#2294)
  8c225550  2023-11-29  Elliott Brooks  Prepare Dart Debug Extension for MV3 release (#2293)
  3bb4a6a6  2023-11-28  Elliott Brooks  Remove old code from before the new Dart Debug Extension (#2290)

Change-Id: Ia219625dce03494620a73272e8d1bde03e2e8aea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339222
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io
Projects
None yet
Development

No branches or pull requests

5 participants