Skip to content

SegString strip and peel throwing OOM exception when problem size > 10**4 #2389

Open

Description

@joshmarshall1

Exact problem size will be dependent on machine size, but running both methods with an problem size larger than 10**4 produce an out of memory error

Reproducer:

    N = 10**5  # Might need increasing depending on machine
    a = ak.random_strings_uniform(8, 2**16, N)
    a.strip("a")  # a.peel("a")

Activity

  1. added
    bug
    on Apr 19, 2023
  2. self-assigned this
    on Sep 8, 2023
  3. removed their assignment
    on Nov 13, 2024
  4. self-assigned this
    on Oct 1, 2025
  5. 1RyanK commented on Oct 1, 2025

    @1RyanK
    Contributor

    I tried running the code and strip worked, so perhaps things have changed since then, but it's worth pointing out that this is going to require using a lot of memory regardless. The inputs to ak.random_strings_uniform are minLen, maxLen, and size. The length is chosen uniformly at random first, so the average string size is going to be somewhere around several thousand bytes. In fact, when I ran it, I did a.nbytes afterwards, which popped out as follows:

    In [5]: a.nbytes
    Out[5]: 3284072539

    For those of us that aren't computers, that's a bit more than 3 GB. Since this has to be copied into a different object, I can't say I'm particularly surprised that this has a decent chance of crashing the server. If you make somewhere around 5 copies of this object, you hit about 16 GB and if that's how much RAM you have available, that's it for the server. Don't forget that if you're running stuff in the background, you have less RAM available than you might realize.

    I'm going to paste in the relevant parts of the Chapel code and let's see what's going on here.

    First place we land is this (in SegmentedMsg.chpl)

      proc segmentedStripMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab): MsgTuple throws {
        var pn = Reflection.getRoutineName();
        var repMsg: string;
    
        var objtype = msgArgs.getValueOf("objType").toUpper(): ObjType;
        var name = msgArgs.getValueOf("name");
    
        // check to make sure symbols defined
        st.checkTable(name);
    
        select (objtype) {
          when (ObjType.STRINGS) {
            var strings = getSegString(name, st);
            var (off, val) = strings.strip(msgArgs.getValueOf("chars"));
            var retString = getSegString(off, val, st);
            repMsg = "created " + st.attrib(retString.name) + "+created bytes.size %?".format(retString.nBytes);
            return new MsgTuple(repMsg, MsgType.NORMAL);
          }
          otherwise {
              var errorMsg = notImplementedError(pn, "%s".format(objtype));
              smLogger.error(getModuleName(),getRoutineName(),getLineNumber(),errorMsg);
              return new MsgTuple(errorMsg, MsgType.ERROR);
          }
        }
      }
    

    You'll notice that it basically kicks the dirty work over to strings.strip, so let's take a look at SegmentedString.chpl

        proc strip(chars: string) throws {
          ref origOffsets = this.offsets.a;
          ref origVals = this.values.a;
          const lengths = this.getLengths();
    
          var replacedLens = makeDistArray(this.offsets.a.domain, int);
    
          forall (off, len, rlen) in zip(origOffsets, lengths, replacedLens) {
            if chars.isEmpty() {
              rlen = interpretAsBytes(origVals, off..#len).strip().size + 1;
            } else {
              rlen = interpretAsBytes(origVals, off..#len).strip(chars:bytes).size + 1;
            }
          }
          var retVals: [makeDistDom(+ reduce replacedLens)] uint(8);
          var retOffs = (+ scan replacedLens) - replacedLens;
    
          forall (off, len, roff) in zip(origOffsets, lengths, retOffs) with (var valAgg = newDstAggregator(uint(8))) {
            var i = 0;
            if chars.isEmpty() {
              for b in interpretAsBytes(origVals, off..#len).strip() {
                valAgg.copy(retVals[roff+i], b:uint(8));
                i += 1;
              }
            } else {
              for b in interpretAsBytes(origVals, off..#len).strip(chars:bytes) {
                valAgg.copy(retVals[roff+i], b:uint(8));
                i += 1;
              }
            }
          }
          return (retOffs, retVals);
        }
    

    There's a couple refs at the top, so those aren't copies. The lengths does involve allocating some memory. It looks like there's a little bit of extra memory usage with the replacedLens, and then (+ scan replacedLens) - replacedLens does that again. But this is all based on the number of strings and there aren't that many strings anyways. Probably the largest use of memory happens on the line var retVals: [makeDistDom(+ reduce replacedLens)] uint(8);.

    It wouldn't surprise me if performance could be improved here. On a whim I decided to check the comm diagnostics for 2 locales and I got this

    In [1]: from arkouda.comm_diagnostics import (start_comm_diagnostics, stop_comm_diagnostics, print_comm_diagnostics_ta
          ⋮ ble, reset_comm_diagnostics)
       ...: 
       ...: N = 10**5
       ...: start_comm_diagnostics()
       ...: a = ak.random_strings_uniform(8, 2**16, N)
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
       ...: 
       ...: reset_comm_diagnostics()
       ...: start_comm_diagnostics()
       ...: a.strip("a")
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |   108 |     8 |            0 |              75 |
    +----+-------+-------+--------------+-----------------+
    |  1 |    16 |   136 |            2 |               0 |
    +----+-------+-------+--------------+-----------------+
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |   435 | 29297 |          436 |              83 |
    +----+-------+-------+--------------+-----------------+
    |  1 |    16 |   114 |            2 |               0 |
    +----+-------+-------+--------------+-----------------+

    The number of gets for locale 0 is out of whack. I wanted to see if it scaled with N so I shrunk the number of bytes per string and tried it like this (on four locales, certainly that will be worse comms... right?):

    In [3]: from arkouda.comm_diagnostics import (start_comm_diagnostics, stop_comm_diagnostics, print_comm_diagnostics_ta
          ⋮ ble, reset_comm_diagnostics)
       ...: 
       ...: N = 10**6
       ...: start_comm_diagnostics()
       ...: a = ak.random_strings_uniform(8, 2**9, N)
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
       ...: 
       ...: reset_comm_diagnostics()
       ...: start_comm_diagnostics()
       ...: a.strip("a")
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |    96 |   977 |            8 |             915 |
    +----+-------+-------+--------------+-----------------+
    |  1 |   213 |  1075 |           11 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  2 |    59 |   837 |           12 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  3 |   475 |   511 |            7 |               3 |
    +----+-------+-------+--------------+-----------------+
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |     4 |   261 |            5 |             249 |
    +----+-------+-------+--------------+-----------------+
    |  1 |    21 |   990 |            8 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  2 |    17 |   120 |            2 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  3 |    29 |  1380 |           17 |               0 |
    +----+-------+-------+--------------+-----------------+

    Okay so maybe the strings are too small...

    In [4]: from arkouda.comm_diagnostics import (start_comm_diagnostics, stop_comm_diagnostics, print_comm_diagnostics_ta
          ⋮ ble, reset_comm_diagnostics)
       ...: 
       ...: N = 10**6
       ...: start_comm_diagnostics()
       ...: a = ak.random_strings_uniform(8, 2**13, N)
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
       ...: 
       ...: reset_comm_diagnostics()
       ...: start_comm_diagnostics()
       ...: a.strip("a")
       ...: stop_comm_diagnostics()
       ...: print_comm_diagnostics_table()
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |    91 |   271 |            5 |             510 |
    +----+-------+-------+--------------+-----------------+
    |  1 |    37 |  1126 |           10 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  2 |   307 |   270 |            4 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  3 |    45 |  1516 |           19 |               0 |
    +----+-------+-------+--------------+-----------------+
    +----+-------+-------+--------------+-----------------+
    |    |   put |   get |   execute_on |   execute_on_nb |
    +====+=======+=======+==============+=================+
    |  0 |    44 |  5237 |           45 |             249 |
    +----+-------+-------+--------------+-----------------+
    |  1 |    17 |   120 |            2 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  2 |   151 | 16148 |          140 |               0 |
    +----+-------+-------+--------------+-----------------+
    |  3 |    16 |   114 |            2 |               0 |
    +----+-------+-------+--------------+-----------------+

    Okay, there's some bad performance. I think maybe the comms are worth looking into here and I will follow up with more on peel when I get the chance.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions