Skip to content

Conversation

@alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Feb 15, 2023

This improves pouchdb-adapter-indexeddb performance for key ranges by:

  • adding a new index ([deleted, id]) to allow for skipping deleted docs by default
  • moving _local/ docs to the META_STORE to simplify allDocs() implementation

TODO

  • batching in allDocs()
  • add _getLocal() implementation
  • rename META_STORE to META_LOCAL_STORE
  • check if getRevisionTree()/doCompaction() need to support local docs
  • resolve trade-off comments
  • resolve TODOs
  • update benchmarks once everything else is done
  • update perf test with: idb-master vs indexeddb-master vs idb-this-pr

Benchmarks

The standard performance test suite was run with:

Client

  "client": {
    "browser": {
      "name": "Chrome Headless",
      "version": "108.0.5359.29",
      "major": "108"
    },
    "device": {},
    "engine": {
      "name": "Blink",
      "version": "108.0.5359.29"
    },
    "cpu": {
      "architecture": "amd64"
    },
    "os": {
      "name": "Linux",
      "version": "x86_64"
    },
    "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/108.0.5359.29 Safari/537.36"
  }

Adapters

  1. idb - pouchdb-adapter-idb as on the current master (30fd84f)
  2. master - pouchdb-adapter-indexeddb as on the current master
  3. this-pr - pouchdb-adapter-indexeddb as on this branch

Results

The full suite was run 51 times, and the lowest median score for each test was taken for each adapter.

Key:

  • Scores are in milliseconds; lower is better.
  • The winning score is marked with !.
  • Where another score is within 5% of the winning score, it is marked with ~.
             |                                 |          idb |       master |      this-pr
-------------|---------------------------------|--------------|--------------|--------------
 basics      | basic-inserts                   |       2.10   |       1.70 ! |       1.80  
             | bulk-inserts                    |      49.35   |      29.20 ! |      32.80  
             | bulk-inserts-large-docs         |     116.00 ~ |     111.80 ! |     112.15 ~
             | bulk-inserts-massive-docs       |    2067.70 ~ |    2054.75 ! |    2059.40 ~
             | basic-updates                   |      78.90 ! |     137.65   |     149.65  
             | basic-gets                      |       1.40   |       1.10 ! |       1.10 !
             | all-docs-skip-limit             |      88.25   |     208.00   |      65.10 !
             | all-docs-startkey-endkey        |      14.55 ! |      28.70   |      17.20  
             | all-docs-keys                   |       8.20   |       4.25 ~ |       4.10 !
             | all-docs-include-docs           |      16.65   |      11.60   |       6.80 !
             | pull-replication-one-generation |    1614.60 ! |    1692.80 ~ |    1624.20 ~
             | pull-replication-two-generation |    1608.30 ! |    1697.40   |    1679.40 ~
-------------|---------------------------------|--------------|--------------|--------------
 views       | temp-views                      |    4603.00 ! |    7012.00   |    4792.30 ~
             | build-secondary-index           |     831.40   |    2020.60   |     785.60 !
             | persisted-views                 |      35.80   |      32.50   |      28.10 !
             | persisted-views-stale-ok        |      15.00   |      16.45   |      12.45 !
-------------|---------------------------------|--------------|--------------|--------------
 find        | create-index                    |   27509.80   |    2246.10   |    1244.50 !
             | simple-find-query               |      11.80   |       4.90 ! |       4.90 !
             | simple-find-query-no-index      |     842.10   |     462.00   |     282.00 !
             | complex-find-query              |    2131.20   |     529.80 ~ |     527.30 !
             | complex-find-query-no-index     |     829.30   |     443.80   |     296.90 !
             | multi-field-query               |    2124.60   |     519.70 ! |     528.10 ~
-------------|---------------------------------|--------------|--------------|--------------
 attachments | basic-attachments               |       8.90 ! |      10.00   |      10.20  

@garethbowen
Copy link
Contributor

@alxndrsn Awesome work! Thanks for the detailed reporting.

Lots of big improvements, and plenty that are break even.

The only one that really stands out is basic-updates. Any idea what's going on there?

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Feb 20, 2023

basic-updates. Any idea what's going on there?

Great question. The test is defined at:

https://github.com/pouchdb/pouchdb/blob/30fd84f1ae88ca8687c2842bd131e67e7cf7c41c/tests/performance/perf.basics.js#L101-L121

So it's measuring bulkDocs() and allDocs(), which is surprising. I'll look into this further.

@alxndrsn
Copy link
Contributor Author

Added new test for local docs with attachments at #8785; maybe useful for this PR as it will separate storage of local docs from other docs.

@alxndrsn alxndrsn marked this pull request as ready for review October 11, 2023 17:46
Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

There are quite a lot of TODO and REVIEW comments which should be addressed one way or the other.

Some ideas inline...

Copy link
Contributor

@SourceR85 SourceR85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logical changes look good to me.

Would be nice, if @garethbowen could take a final look at these changes.

Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just readability fixes - the rest looks great.

@garethbowen
Copy link
Contributor

@alxndrsn Any idea why this change makes the views perform worse?

views       | temp-views                      |         5099.90 ! |         6630.30       
-           | build-secondary-index           |         1547.10 ! |         1847.30       
-           | persisted-views                 |           33.90 ! |           36.45       
-           | persisted-views-stale-ok        |           17.25 ~ |           16.95 ~   

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 3, 2024

@alxndrsn Any idea why this change makes the views perform worse?

Great question, looking into this.

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 3, 2024

@garethbowen I've re-run perf test suites basic and temp-views with Chromium 108, which looks to have been the version used for the results in the original PR message.

Branches used represent master and this PR at the time of opening this PR, and master and this PR in the present day:

  • Using stat: median
  • Client: Chrome Headless 108
  • Adapter: indexeddb
  • Versions tested:
    1. 30fd84f - master - historic
    2. acc12f6 - master - today
    3. 18f706f - this PR - today
    4. c361764 - this PR - historic
-           | -                               | itr |         #1 | itr |         #2 | itr |         #3 | itr |         #4
-------------------------------------------------------------------------------------------------------------------------
basics      | basic-inserts                   |  22 |     1.80 ~ |  22 |     1.80 ~ |  22 |     1.80 ~ |  22 |     1.80 ~
-           | bulk-inserts                    |  22 |    34.22 ~ |  22 |    34.80 ~ |  22 |    61.75   |  22 |    60.92  
-           | bulk-inserts-large-docs         |  22 |   119.32 ~ |  22 |   124.70 ~ |  22 |   180.17   |  22 |   180.62  
-           | bulk-inserts-massive-docs       |  22 |  2091.82 ~ |  22 |  2083.63 ~ |  22 |  2076.68 ~ |  22 |  2094.50 ~
-           | basic-updates                   |  22 |   154.25 ~ |  22 |   148.60 ~ |  22 |   159.23   |  22 |   159.07  
-           | basic-gets                      |  22 |     1.10 ~ |  22 |     1.10 ~ |  22 |     1.10 ~ |  22 |     1.10 ~
-           | all-docs-skip-limit             |  22 |   218.67   |  22 |   217.00   |  22 |    73.25   |  22 |    67.57 !
-           | all-docs-startkey-endkey        |  22 |    31.25   |  22 |    31.38   |  22 |    18.13 ~ |  22 |    18.38 ~
-           | all-docs-keys                   |  22 |     4.65   |  22 |     4.50 ~ |  22 |     4.40 ~ |  22 |     4.40 ~
-           | all-docs-include-docs           |  22 |    12.35   |  22 |    12.40   |  22 |     8.80   |  22 |     7.13 !
-           | pull-replication-one-generation |  22 |  1778.05 ~ |  22 |  1730.90 ~ |  22 |  1822.25   |  22 |  1817.10 ~
-           | pull-replication-two-generation |  22 |  1830.80 ~ |  22 |  1825.25 ~ |  22 |  1844.70 ~ |  22 |  1852.30 ~
-------------------------------------------------------------------------------------------------------------------------
views       | temp-views                      |  22 |  7033.05 ! |  22 |  7488.70   |  22 | 11233.55   |  22 | 11202.45  
-           | build-secondary-index           |  22 |  2345.30 ~ |  22 |  2301.40 ~ |  22 |  3051.20   |  22 |  3415.40  
-           | persisted-views                 |  22 |    36.00   |  22 |    38.20   |  22 |    39.98   |  22 |    34.05 !
-           | persisted-views-stale-ok        |  22 |    18.30   |  22 |    18.50   |  22 |    20.03   |  22 |    16.17 !

  * itr = test iterations

It shows slowdown for this branch for temp-views, likely because the temp views involve a massive amount of bulkDocs() calls, which shows slowdown in the basics suite.

What's weird is that the original results shared in the PR showed so much improvement in temp-views. I don't have a satisfactory explanation for that.

The slowdown is cause for some concern, but perhaps it doesn't matter? Pouch docs read:

Temporary queries are very slow, and we only recommend them for quick debugging during development.

@garethbowen
Copy link
Contributor

I agree that temp views aren't a big concern (at least for me!) but build-secondary-index is, right? The initial results had this beating master and idb and now it's gone the other way.

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 3, 2024

I agree that temp views aren't a big concern (at least for me!) but build-secondary-index is, right? The initial results had this beating master and idb and now it's gone the other way.

As above, I'm also confused by this. I think I have a separate fix which reduces the impact significantly... but also applies to the master version 😁 Benchmarking in progress...

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 4, 2024

@garethbowen I've deleted the seq index from map-reduce databases, as it's not required there. This seems to have reduced the impact. However, it's worth noting this change could also be applied to the current master, with significant effect:

  • Using stat: min
  • Client: Chrome Headless 123
  • Adapters:
    1. indexeddb - 5bc8f31 - master
    2. indexeddb - 6e52efe - master with seq index
    3. indexeddb - a8b0c63 - this pr
-           | -                               | itr |         #1 | itr |         #2 | itr |         #3
------------------------------------------------------------------------------------------------------
basics      | basic-inserts                   |  20 |     1.20 ~ |  20 |     1.20 ~ |  20 |     1.40  
-           | bulk-inserts                    |  20 |    23.15 ~ |  20 |    23.55 ~ |  20 |    27.30  
-           | bulk-inserts-large-docs         |  20 |    36.45   |  20 |    33.00 ! |  20 |    77.40  
-           | bulk-inserts-massive-docs       |  20 |  1766.65 ~ |  20 |  1767.65 ~ |  20 |  1763.15 ~
-           | basic-updates                   |  20 |   114.80 ~ |  20 |   118.55 ~ |  20 |   120.80 ~
-           | basic-gets                      |  20 |     1.10 ~ |  20 |     1.10 ~ |  20 |     1.10 ~
-           | all-docs-skip-limit             |  20 |   190.15   |  20 |   191.65   |  20 |    54.45 !
-           | all-docs-startkey-endkey        |  20 |    29.30   |  20 |    29.30   |  20 |    15.85 !
-           | all-docs-keys                   |  20 |     3.60 ~ |  20 |     3.70   |  20 |     3.50 ~
-           | all-docs-include-docs           |  20 |    11.00   |  20 |    10.95   |  20 |     7.30 !
-           | pull-replication-one-generation |  20 |  1710.70 ~ |  20 |  1738.60 ~ |  20 |  1783.50 ~
-           | pull-replication-two-generation |  20 |  1720.20 ~ |  20 |  1734.40 ~ |  20 |  1760.10 ~
------------------------------------------------------------------------------------------------------
views       | temp-views                      |  20 |  5130.60   |  20 |  4182.90 ! |  20 |  6053.70  
-           | build-secondary-index           |  20 |  1556.80   |  20 |  1151.30 ! |  20 |  1705.60  
-           | persisted-views                 |  20 |    33.70 ~ |  20 |    33.20 ~ |  20 |    33.75 ~
-           | persisted-views-stale-ok        |  20 |    16.45 ~ |  20 |    15.85 ~ |  20 |    16.70  
------------------------------------------------------------------------------------------------------
find        | create-index                    |  20 |  1530.80   |  20 |  2349.80   |  20 |  1148.20 !
-           | simple-find-query               |  20 |     5.10   |  20 |     4.40 ! |  20 |     4.80  
-           | simple-find-query-no-index      |  20 |   408.30   |  20 |   424.00   |  20 |   307.10 !
-           | complex-find-query              |  20 |   461.10 ~ |  20 |   462.40 ~ |  20 |   463.10 ~
-           | complex-find-query-no-index     |  20 |   399.60   |  20 |   396.20   |  20 |   311.10 !
-           | multi-field-query               |  20 |   461.70 ~ |  20 |   453.70 ~ |  20 |   465.30 ~
------------------------------------------------------------------------------------------------------
attachments | basic-attachments               |  20 |     8.30 ~ |  20 |     8.35 ~ |  20 |     8.60 ~
-           | many-attachments-base64         |  20 |    55.65 ~ |  20 |    56.45 ~ |  20 |    55.75 ~
-           | many-attachments-binary         |  20 |     5.10 ~ |  20 |     5.10 ~ |  20 |     5.00 ~

  * itr = test iterations

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 4, 2024

  • Using stat: min
  • Client: Chrome Headless 123
  • Adapters:
    1. idb - 9ba277b - master
    2. indexeddb - 9ba277b - master
    3. indexeddb - 4fd2f51 - this pr
-           | -                               | itr |         #1 | itr |         #2 | itr |         #3
------------------------------------------------------------------------------------------------------
basics      | basic-inserts                   |  10 |     1.60   |  10 |     1.20 ! |  10 |     1.30  
-           | bulk-inserts                    |  10 |    53.45   |  10 |    23.55 ! |  10 |    27.45  
-           | bulk-inserts-large-docs         |  10 |   139.60   |  10 |    41.20 ! |  10 |    64.40  
-           | bulk-inserts-massive-docs       |  10 |  1769.70 ~ |  10 |  1762.70 ~ |  10 |  1772.45 ~
-           | basic-updates                   |  10 |   116.30 ~ |  10 |   118.30 ~ |  10 |   126.30  
-           | basic-gets                      |  10 |     1.40   |  10 |     1.10 ~ |  10 |     1.10 ~
-           | all-docs-skip-limit             |  10 |    78.60   |  10 |   190.65   |  10 |    55.00 !
-           | all-docs-startkey-endkey        |  10 |    13.30 ! |  10 |    28.90   |  10 |    15.55  
-           | all-docs-keys                   |  10 |     6.80   |  10 |     3.60 ~ |  10 |     3.60 ~
-           | all-docs-include-docs           |  10 |    15.00   |  10 |    11.35   |  10 |     7.25 !
-           | pull-replication-one-generation |  10 |  1545.60 ! |  10 |  1762.70   |  10 |  1787.60  
-           | pull-replication-two-generation |  10 |  1581.40 ! |  10 |  1739.60   |  10 |  1790.70  
------------------------------------------------------------------------------------------------------
views       | temp-views                      |  10 |  3954.00 ! |  10 |  5126.90   |  10 |  6281.80  
-           | build-secondary-index           |  10 |   664.60 ! |  10 |  1527.50   |  10 |  1614.20  
-           | persisted-views                 |  10 |    32.45 ~ |  10 |    33.55 ~ |  10 |    33.60 ~
-           | persisted-views-stale-ok        |  10 |    13.85 ! |  10 |    16.30   |  10 |    16.45  
------------------------------------------------------------------------------------------------------
find        | create-index                    |  10 | 19660.30   |  10 |  1714.30   |  10 |  1069.10 !
-           | simple-find-query               |  10 |    10.30   |  10 |     5.00 ! |  10 |     5.60  
-           | simple-find-query-no-index      |  10 |   736.20   |  10 |   415.60   |  10 |   312.70 !
-           | complex-find-query              |  10 |  1813.50   |  10 |   458.30 ~ |  10 |   471.80 ~
-           | complex-find-query-no-index     |  10 |   719.40   |  10 |   399.60   |  10 |   314.50 !
-           | multi-field-query               |  10 |  1909.80   |  10 |   455.70 ~ |  10 |   463.00 ~
------------------------------------------------------------------------------------------------------
attachments | basic-attachments               |  10 |     7.10 ! |  10 |     8.30   |  10 |     8.60  
-           | many-attachments-base64         |  10 |    61.30   |  10 |    55.15 ~ |  10 |    54.45 ~
-           | many-attachments-binary         |  10 |     7.50   |  10 |     5.10 ~ |  10 |     5.10 ~

  * itr = test iterations

Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One naming suggestion, and two left over suggestions from a previous review, then I think this is ready to go.

@SourceR85 SourceR85 dismissed their stale review April 5, 2024 11:25

Style change is postponed

Copy link
Contributor

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready when you are. Great work on this!

@alxndrsn
Copy link
Contributor Author

alxndrsn commented Apr 9, 2024

@garethbowen I've made a small update to getAttachment()'s handling of local docs to bring it more into line with the idb and memory adapters. I've also added a couple of extra tests around this functionality.

Please note that this marks a change from the behaviour of the indexeddb adapter in master - getAttachment() would previously return attachments on local docs iff using the indexeddb adapter. This behaviour did not seem to be intentional - as far as I can tell, correct behaviour/support of attachments on local docs is not specified in PouchDB.

@alxndrsn alxndrsn merged commit 2789b70 into apache:master Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants