Skip to content

Crashes with every file larger than aproximately around 200 KB #16

Open

Description

@johannesjo

Using angular 1.2.0 I ran into the issue that chrome and also firefox tend to crash for every file a little larger than a few Kilobytes. Any idea how to circumvent that?

Activity

  1. mrsean2k commented on Mar 14, 2014

    @mrsean2k

    I'm not certain if this is the same issue, but on Chrome / Angular, the performance drops off severely for even moderately sized images.

    I believe I've traced the issue to the doResizing function:

      var doResizing = function(imageResult, callback) {
          createImage(imageResult.url, function(image) {
             var dataURL = resizeImage(image, scope);
              imageResult.resized = {
                  dataURL: dataURL,
                  type: dataURL.match(/:(.+\/.+);/)[1],
              };
              callback(imageResult);
          });
      };
    

    executing that particular regular expression on the dataURL.match line takes a great deal of resource - on a 32Gb iMac, it was taking minutes at a time to process a ~1Mb file, and could easlly appear as if it had crashed. I had to ignore injunctions to kill the page 3 or 4 times but it does complete eventually.

    Fortunately the fix is easy, using the DataURI spec. as a reference, just replace the match with a simple substring:

      var doResizing = function(imageResult, callback) {
          createImage(imageResult.url, function(image) {
              var dataURL = resizeImage(image, scope);
              var imageType = dataURL.substring(5, dataURL.indexOf(';'));
              imageResult.resized = {
                  dataURL: dataURL,
                  type: imageType
              };
              callback(imageResult);
          });
      };
    

    This has reduced the processing time to < 1 sec. for everything I've tried it on so far.

  2. boxxxie commented on Mar 18, 2014

    @boxxxie

    can you do a PR?

  3. mrsean2k commented on Mar 18, 2014

    @mrsean2k

    Hi, unless I've made a mess of it, I should already have added one, PR#25 I think? Unfamiliar with the process so apologies if I've got things out of sequence.

  4. boxxxie commented on Mar 18, 2014

    @boxxxie

    sorry, i don't see the PR being referred to in this issue. so it wasn't obvious.

    #25
    000a7ff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions