使用json字符串而不是子树 [英] using json strings instead of children subtrees

查看:93
本文介绍了使用json字符串而不是子树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库结构:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $和〜5级深
child2
子树〜10个孩子和〜5级深
...

现在我永远只能得到/设置整个孩子,也就是说,我永远不需要在孩子的子树中直接引用一个ref。



我的问题是,在这种情况下,在速度和/或空间方面,将每个子树存储为JSON字符串并转换为客户端/ >

谢谢

解决方案我曾多次在Firebase数据库中存储JSON字符串:


  • 来存储GeoJSON功能;和
  • 来存储每个用户的应用程序设置。

    $ b

    GeoJSON以字符串形式存储因为这种格式广泛使用了坐标数组。应用程序设置有大量的嵌套。



    在这两种情况下,就Firebase而言,数据是不透明的,不需要其内容查询。

    我对Firebase的内部知识并不了解,但是我非常怀疑您会看到存储JSON字符串的任何效率或性能优势。事实上,效率(也可能是性能)可能会更糟。您可以接近确定Firebase不会将其内部数据存储为JSON。这意味着在将数据存储为JSON字符串时,您可能正在存储更多的数据,因为除了这些值之外,JSON还将包含这些键。这些数据还将包括大括号,引号和转义等。

    如果数据较大,则需要在整个网络上传输更多信息,这样做无法提高性能。

    你可能想自己做一些分析。只要创建数据库充满未编码的数据和另一个完整的JSON字符串,并比较大小差异。控制台中的用法选项卡将显示整体数据库大小。如果您对实际传输的内容感兴趣,请使用Chrome开发工具(或类似的工具)查看网络标签上的网络套接字流量。



    简而言之,如果效率和性能是考虑存储JSON字符串的唯一原因,那么您可能不希望这样做。


    I have a database structure like:

    base
      child1
         sub tree of ~10 children and ~5 levels deep
      child2
         sub tree of ~10 children and ~5 levels deep
      ...
    

    now I always only get/set whole children, that is I will never need a ref pointing inside the children's sub tree directly.

    my question is, in this case, will it be more efficient in terms of speed and/or space to store each subtree as a JSON string and convert to/from on the client ?

    thanks

    解决方案

    I've stored JSON strings in Firebase databases on several occasions:

    • to store GeoJSON features; and
    • to store each user's application settings.

    The GeoJSON was stored as a string primarily because of that format's extensive use of arrays for coordinates. And the application settings had a significant amount of nesting.

    In both situations, the data was opaque as far as Firebase was concerned and there was no need for its content to be queried.

    I have no knowledge of Firebase's internals, but I very much doubt you will see any efficiency or performance benefits from storing JSON strings. In fact, efficiency (and possibly performance) will likely be worse. You can be close to certain that Firebase does not store its internal data as JSON. That means that in storing data as JSON strings, you are likely to be storing more data, as the JSON will contain the keys in addition to the values. And that data will also include braces, quotes and escapes, etc.

    If the data is larger, more information will need to be transferred across the network and that cannot help performance.

    You might want to do some profiling yourself. Just create database full of unencoded data and another full of JSON strings and compare the size difference. The 'Usage' tab in the console will give you an indication of overall database size. And if you are interested in what's actually transferred, use the Chrome Dev Tools (or similar) to have a look at the web socket traffic on the 'Network' tab.

    In short, if efficiency and performance are your only reasons for considering storing JSON strings, you probably won't want to do it.

    这篇关于使用json字符串而不是子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆