def _calculate_per_thread_extra_bytes():
    """Calculates how many extra bytes are added to the serialized form of the threads JSON array
    when adding a new thread, excluding the bytes for serializing the thread id and name themselves.

    This is used below by the PostFixBuffer abstraction to help calculate the number of bytes the serialized form
    of the PostFixBuffer will take, without having to actually serialize it.  It was found that doing the heavy
    weight process of serializing it over and over again to just get the size was eating too much CPU.

    @return: An array of two int entries.  The first entry is how many extra bytes are added when adding the
        first thread to the threads JSON array and the second is how many extra bytes are added for all subsequent
        threads.  (The number differences by at least one due to the need for a comma to be inserted).
    @rtype: [int]
    """
    # An array of the number of bytes used to serialize the array when there are N threads in it (where N is the
    # index into size_by_entries).
    sizes_by_entries = []

    # Calculate sizes_by_entries by actually serialzing each case.
    threads = []
    test_string = 'A'
    for i in range(3):
        sizes_by_entries.append(len(json_lib.serialize(threads)))
        # Add in another thread for the next round through the loop.
        threads.append({'id': test_string, 'name': test_string})

    # Now go back and calculate the deltas between the different cases.  We have to remember to subtract
    # out the length due to the id and name strings.
    test_string_len = len(json_lib.serialize(test_string))
    result = []
    for i in range(1, 3):
        result.append(sizes_by_entries[i] - sizes_by_entries[i - 1] - 2 * test_string_len)

    return result
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/scalyr_client.py/_calculate_per_thread_extra_bytes/original