]> Kevux Git Server - fll/commitdiff
Bugfix: Performance is slow due to process signal checks (more).
authorKevin Day <thekevinday@gmail.com>
Thu, 9 Dec 2021 05:43:42 +0000 (23:43 -0600)
committerKevin Day <thekevinday@gmail.com>
Thu, 9 Dec 2021 05:43:42 +0000 (23:43 -0600)
This is a follow up to the previous commit similarly named.
I forgot to hit the save button for the changes to FSS Basic List files in my editor.

The cost of the system call for checking if a signal is received is more expensive than I have previously imagined.
I also was not sure where I should handle the signals and I arbitrarily put them inside loops.

Reduce the number of checks.
Reduce the number of the system call to check the process signal using modulus math.

The performance difference is most notable when using the byte_dump program.

This focuses on solving the immediate performance bug.
I still have not done any extensive performance investigations and I expect this to still have significant room for improvement.

level_3/fss_basic_list_read/c/fss_basic_list_read.c
level_3/fss_basic_list_read/c/private-fss_basic_list_read.c

index 67822a33f7120e52ce3945aaecb83733c3a3cb40..eee0d8f86471370c41e4a3045b31d789a4d3edfa 100644 (file)
@@ -344,15 +344,20 @@ extern "C" {
       if (F_status_is_error_not(status) && main->parameters[fss_basic_list_read_parameter_delimit].result == f_console_result_additional) {
         f_array_length_t location = 0;
         f_array_length_t length = 0;
+        uint16_t signal_check = 0;
 
         // Set the value to 0 to allow for detecting mode based on what is provided.
         data.delimit_mode = 0;
 
         for (f_array_length_t i = 0; i < main->parameters[fss_basic_list_read_parameter_delimit].values.used; ++i) {
 
-          if (fss_basic_list_read_signal_received(main)) {
-            status = F_status_set_error(F_interrupt);
-            break;
+          if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+            if (fss_basic_list_read_signal_received(main)) {
+              status = F_status_set_error(F_interrupt);
+              break;
+            }
+
+            signal_check = 0;
           }
 
           location = main->parameters[fss_basic_list_read_parameter_delimit].values.array[i];
@@ -544,12 +549,17 @@ extern "C" {
       if (F_status_is_error_not(status) && main->remaining.used > 0) {
         f_file_t file = f_file_t_initialize;
         f_array_length_t size_file = 0;
+        uint16_t signal_check = 0;
 
         for (f_array_length_t i = 0; i < main->remaining.used; ++i) {
 
-          if (fss_basic_list_read_signal_received(main)) {
-            status = F_status_set_error(F_interrupt);
-            break;
+          if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+            if (fss_basic_list_read_signal_received(main)) {
+              status = F_status_set_error(F_interrupt);
+              break;
+            }
+
+            signal_check = 0;
           }
 
           data.files.array[data.files.used].range.start = data.buffer.used;
index 8a565f5a6cbf812ac03d6a72d9446a4ed2b1bb15..be29ee8ad5495947ed4488e66601158bd8259ce0 100644 (file)
@@ -82,11 +82,16 @@ extern "C" {
     f_array_length_t position_depth = 0;
     f_array_length_t position_at = 0;
     f_array_length_t position_name = 0;
+    uint16_t signal_check = 0;
 
     for (f_array_length_t i = 0; i < data->depths.used; ++i) {
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       data->depths.array[i].depth = 0;
@@ -171,8 +176,12 @@ extern "C" {
 
       for (f_array_length_t j = i + 1; j < data->depths.used; ++j) {
 
-        if (fss_basic_list_read_signal_received(main)) {
-          return F_status_set_error(F_interrupt);
+        if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+          if (fss_basic_list_read_signal_received(main)) {
+            return F_status_set_error(F_interrupt);
+          }
+
+          signal_check = 0;
         }
 
         if (data->depths.array[i].depth == data->depths.array[j].depth) {
@@ -438,6 +447,7 @@ extern "C" {
     f_array_lengths_t except_none = f_array_lengths_t_initialize;
     f_array_lengths_t *delimits_object = fss_basic_list_read_delimit_object_is(0, data) ? &data->delimits_object : &except_none;
     f_array_lengths_t *delimits_content = fss_basic_list_read_delimit_content_is(0, data) ? &data->delimits_content : &except_none;
+    uint16_t signal_check = 0;
 
     if (data->option & fss_basic_list_read_data_option_raw_d) {
       delimits_object = &except_none;
@@ -448,8 +458,12 @@ extern "C" {
 
       if (!names[i]) continue;
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       fss_basic_list_read_print_at(main, i, *delimits_object, *delimits_content, data);
@@ -485,13 +499,18 @@ extern "C" {
 
     f_array_length_t at = 0;
     f_status_t status = F_none;
+    uint16_t signal_check = 0;
 
     for (f_array_length_t i = 0; i < data->objects.used; ++i) {
 
       if (!names[i]) continue;
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       if (at == data->depths.array[0].value_at) {
@@ -552,13 +571,18 @@ extern "C" {
     }
 
     f_array_length_t max = 0;
+    uint16_t signal_check = 0;
 
     for (f_array_length_t at = 0; at < data->contents.used; ++at) {
 
       if (!names[at]) continue;
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       if (data->contents.array[at].used > max) {
@@ -602,6 +626,7 @@ extern "C" {
 
       f_string_range_t range = f_string_range_t_initialize;
       f_array_length_t i = 0;
+      uint16_t signal_check = 0;
 
       range.start = data->contents.array[at].array[0].start;
       range.stop = data->contents.array[at].array[0].stop;
@@ -613,8 +638,12 @@ extern "C" {
 
       for (i = range.start; i <= range.stop; ++i) {
 
-        if (fss_basic_list_read_signal_received(main)) {
-          return F_status_set_error(F_interrupt);
+        if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+          if (fss_basic_list_read_signal_received(main)) {
+            return F_status_set_error(F_interrupt);
+          }
+
+          signal_check = 0;
         }
 
         if (data->buffer.string[i] == f_string_eol_s[0]) {
@@ -685,13 +714,18 @@ extern "C" {
 
     f_array_length_t line = 0;
     f_status_t status = F_none;
+    uint16_t signal_check = 0;
 
     for (f_array_length_t i = 0; i < data->contents.used; ++i) {
 
       if (!names[i]) continue;
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       status = fss_basic_list_read_process_at_line(main, i, *delimits_object, *delimits_content, data, &line);
@@ -798,13 +832,18 @@ extern "C" {
     f_array_length_t total = 0;
     f_string_range_t range = f_string_range_t_initialize;
     f_array_length_t i = 0;
+    uint16_t signal_check = 0;
 
     for (f_array_length_t at = 0; at < data->contents.used; ++at) {
 
       if (!names[at]) continue;
 
-      if (fss_basic_list_read_signal_received(main)) {
-        return F_status_set_error(F_interrupt);
+      if (!((++signal_check) % fss_basic_list_read_signal_check_d)) {
+        if (fss_basic_list_read_signal_received(main)) {
+          return F_status_set_error(F_interrupt);
+        }
+
+        signal_check = 0;
       }
 
       if (data->option & fss_basic_list_read_data_option_object_d) {