Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question IndexedDB API 2.0 in WebGL

Discussion in 'Web' started by nguyenducthuanse, Sep 18, 2023.

  1. nguyenducthuanse

    nguyenducthuanse

    Joined:
    Jan 17, 2021
    Posts:
    6
    Hi,
    I'm newer on WebGL platform, I'm a bit confused about IndexedDB API 2.0.
    Does Unity WebGL support IndexedDB API 2.0?
    Hopefully, someone can answer or share a related document.
    Many Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,330
    It uses IndexedDB internally, for example to store PlayerPrefs data and caching, but this isn't exposed to C# so it doesn't matter which version it is. The PlayerPrefs storage is also limited to 1 MB.

    This is everything the manual provides about IndexedDB:
    https://docs.unity3d.com/Manual/30_search.html?q=IndexedDB
     
    nguyenducthuanse likes this.
  3. nguyenducthuanse

    nguyenducthuanse

    Joined:
    Jan 17, 2021
    Posts:
    6
    @CodeSmile, thank you for your answers.
    As I know, IndexedDB 2.0 will provide some API that may increase the loading speed like getAll().
    But in .framework.js is generated when building WebGL, I see this js file only using get() and put() method of IndexedDB, which is a bit confusing.
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    951
    Unity uses IndexedDB in three different ways:
    - Emscripten IDBFS filesystem that is implemented at https://github.com/emscripten-core/emscripten/blob/main/src/library_idbfs.js . For persisting savegame data. This is the one that you are seeing in framework.js file.
    - UnityCache.js: for caching network request metadata. (Network request file data is cached in Cache API instead)
    - WebGPU shader cache.

    It looks like WebGPU shader cache does use the .getAll() function, but Emscripten IDBFS and UnityCache do not.

    Are you seeing performance issues in this area? (If you are knowledged in IndexedDB internals and have a strong opinion in how it should work, then if you want to modify the Emscripten project with some optimizations to their IDBFS filesystem and do a PR to them, that would be picked up by Unity in a future compiler update)
     
    nguyenducthuanse likes this.
  5. nguyenducthuanse

    nguyenducthuanse

    Joined:
    Jan 17, 2021
    Posts:
    6
    jukka_j , thank you for your detail answer.
    As such Untiy WebGL does not use getAll() of the IndexedDB API 2.0 for the Cache API.

    Oh No, as said above I'm just a Newbie on WebGL platform, I just want to know about IndexedDB and the improvements in IndexedDB API 2.0 and the way that Unity is using these improvements. And your answer is enough for me.
    Many thanks!