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

nvs_* getting slower updage from 5.2.1 to 5.3 or 5.4 (IDFGH-14424) #15204

Open
3 tasks done
GuGu927 opened this issue Jan 14, 2025 · 2 comments
Open
3 tasks done

nvs_* getting slower updage from 5.2.1 to 5.3 or 5.4 (IDFGH-14424) #15204

GuGu927 opened this issue Jan 14, 2025 · 2 comments
Assignees
Labels
Status: Opened Issue is new

Comments

@GuGu927
Copy link

GuGu927 commented Jan 14, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

Hi. I'm using NVS to save device data, and have speed problem when update to latest verion of IDF.

When IDF version 5.2.1, nvs_* works very fast.

nvs_set_* over 10 times each create
I (71606) device: Child created
I (71656) device: Child created
I (71746) device: Child created
I (71796) device: Child created

nvs_erase_* over 10 times each delete
I (37796) device: Child deleted
I (37816) device: Child deleted
I (37826) device: Child deleted
I (37846) device: Child deleted

When IDF version to 5.3.2 and 5.4, nvs_* works very slow

nvs_set* over 10 times each create
I (192097) device: Child created
I (192507) device: Child created

nvs_erase_* over 10 times each delete
I (101024) device: Child deleted
I (101864) device: Child deleted
I (102704) device: Child deleted
I (103554) device: Child deleted
I (104404) device: Child deleted

Enable/disable NVS_ALLOCATE_CACHE_IN_SPIRAM not affect.

Everythings is same but not IDF version.

Can you help me with this?
Thanks.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 14, 2025
@github-actions github-actions bot changed the title nvs_* getting slower updage from 5.2.1 to 5.3 or 5.4 nvs_* getting slower updage from 5.2.1 to 5.3 or 5.4 (IDFGH-14424) Jan 14, 2025
@rrtandler
Copy link
Collaborator

Hi @GuGu927 ,
Could you please provide the code snippet showing how is the NVS called and how are you measuring the time elapsed in the operation. And, if possible, also the actual number of entries already stored in NVS during the test ?

@espressif-bot espressif-bot assigned rrtandler and unassigned pacucha42 Jan 15, 2025
@GuGu927
Copy link
Author

GuGu927 commented Jan 15, 2025

Hi @rrtandler ,
I'm using ESP32S3 N8R8.
Here's code flow of mine.

esp_err_t set_storage_bool(nvs_handle_t *handle, const char *key, bool value)
{
    esp_err_t err = nvs_set_u8(*handle, key, (uint8_t)value);
    if (err != ESP_OK)
    {
    }
    else
        my_commit(handle);
    return err;
}

esp_err_t get_storage_bool(nvs_handle_t *handle, const char *key, bool *value)
{
    uint8_t nvs_value;
    esp_err_t err = nvs_get_u8(*handle, key, &nvs_value);
    if (err != ESP_OK)
    {
        return err;
    }
    *value = (bool)nvs_value;
    return err;
}

void my_commit(nvs_handle_t *handle)
{
// Loop the handle list, and if it exists, try `vTaskDelete`. After that, call `xTaskCreate`. 
// Commit the task after some seconds. This prevents `nvs_commit` from happening multiple times at the same time.

}

esp_err_t save_device()
{
  set_some_nvs_blob()
  my_commit()
}

my_device_t *create_device()
{
  realloc device list
  get_some_nvs_value() != ESP_OK then set_some_nvs_value()
  get_some_nvs_value() != ESP_OK then set_some_nvs_value()
  get_some_nvs_value() != ESP_OK then set_some_nvs_value()
  ...
  printf("Device created");
  save_device(my_device);
  return my_device;
}
  1. Data comes in.
  2. Check for loop and try to create my virtual device.
  3. Reallocate memory for the device list.
  4. Attempt nvs_get_* for many (5–20) properties of the device being added. If a value is missing, set it using nvs_set_*.
    (When first booting, devices are loaded from NVS, so the flow always tries both nvs_get_* and nvs_set_* simultaneously.)
  5. At the very end, use printf to output "device created," then save the device.
  6. Check data.

After every nvs_set, a my_commit is attempted.
In IDF version 5.2.1, the interval shown by printf in the console time is in the tens of milliseconds.
In IDF version 5.3.X and 5.4, the interval shown by printf in the console time is in the hundreds of milliseconds.

If you need any additional information, please don't hesitate to ask. I can provide detailed reproduction steps or logs if necessary. Thank you for reviewing this issue, and I look forward to your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

4 participants