-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Revert "build: Use Homebrew's sqlite package if it is available" #25985
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
Conversation
This reverts ee7b84e from bitcoin#20527. This change was made without any rationale, maybe other than a brew installed version might be newer, and that's "better". However when building from source on macOS, it just results in drastically worse perofrmance, and results in issues / confusions like bitcoin#25724. Resolves the "build from source" portion of bitcoin#25724. Building from depends is still not ideal, however I have some other changes that might help improve things in that case. The difference in performance can be observed using the example from bitcoin#25724 (comment), but minified to only 10 descriptors. i.e: ```bash time src/bitcoin-cli createwallet speedy true time src/bitcoin-cli importdescriptors '[ {"desc":"raw(00145846369f3d6ba366d6f5a903fb5cf4dca3763c0e)#k9wh6v62","timestamp":"now"}, {"desc":"raw(001420800aabf13f3a4c4ce3ce4c66cecf1d17f21a6e)#6m0hlfh4","timestamp":"now"}, {"desc":"raw(0014c6bf9715e06d73ebf9b3b02d5cc48d24d8bbabc1)#wyavh36r","timestamp":"now"}, {"desc":"raw(00141ba7807b3f46af113beaea5c698428ce7138cd8a)#jctdsups","timestamp":"now"}, {"desc":"raw(00140c1bd27f10fff01b36ddf3c1febaa1acff19b080)#9s6nc3pk","timestamp":"now"}, {"desc":"raw(00141226e31987e4bc2e63c0ee12908f675e40464b20)#9pp7qm39","timestamp":"now"}, {"desc":"raw(0014f73f149f7503960a5e849c6ee7a8a8c336f631cb)#qtkxv9fc","timestamp":"now"}, {"desc":"raw(0014c8ccb4d81ffc769fc5fdd8d7eed69b0e0cae5749)#hn39qayv","timestamp":"now"}, {"desc":"raw(001498565aead2d67a22a6021d55210f2a917fc22169)#6ar3vwsx","timestamp":"now"}, {"desc":"raw(001403013248ac0cd9eabe176cad162cda2a19f771e1)#4m47mukd","timestamp":"now"} ]' ``` Running master, when building from souce and using brew installed sqlite, this takes ~3.4s. With this PR, the same operation takes ~0.3s.
It would be nice if we could figure out why macOS SQLite is different from self built so that we can replicate those performance improvements in our depends build. |
Concept ACK The Homebrew docs recommend to "not remove macOS native tools and forcefully replace them with symlinks back to the Homebrew-provided tool." But I couldn't find anything on whether MacOS's version of SQLite is different to the brew version of SQLite (assuming the same version numbers). That difference in performance is surely not entirely explained by different version numbers being used. |
Concept ACK it's not correct to say there was "no rationale", it's in the pr description:
But we now know we'd prefer not to use the brew version. |
I agree. Started having a look through https://github.com/apple-oss-distributions to see if there might be any clues.
The description just says we should prefer brew installed sqlite if it happens to be installed. There's no reasoning given as to why we should prefer that instead of just using the system library (i.e it's faster, has newer features we require, system libs are severely outdated/buggy) etc. |
What is the sqlite version on macOS 10.15? |
Tested d216d71 On the first machine the system library is twice as fast, on the second machine there's no difference (or it's even slightly slower). I checked in the log that right Sqlite version was indeed used. I agree with @hebasto that we should check if this holds for older (supported) macOS versions. Perhaps a safer approach is to pick whichever version is higher. Machine 1 MacBook Pro (2.3 GHz 8-Core Intel Core i9), macOS 12.5.1
Machine 2: iMac (3.4 GHz Quad-Core Intel Core i5): macOS 12.5.1
Note that machine 2 is much slower than machine 1, yet sqlite performs faster. There's something else going on, possibly specific to my setup. I got even more extreme results with the |
NACK. More often than not, that would just result in the situation where we get worse performance. We aren't using features from newer versions, and Apple already backports bug and security fixes to the system libs. |
Looks like it is 3.28.0+. |
So this is preferring the macOS/native sqlite over the Homebrew sqlite, right? Can the user still explicitly override it and build with Homebrew's if they so choose? ( |
Yes. See also #25724.
If by "made available", you mean a
Yes. The user can ultimately still choose whichever sqlite they prefer. i.e set |
Not sure if this issue applies to arm64 (intel only) or if I'm testing incorrectly. Installed sqlite3 from homebrew and I'm not seeing a difference between master and this branch on a MacBook Pro 16 (M1 Max), macOS 12.3. In both cases the example takes 5 seconds. Tested back and forth a few times.
|
Ah, the system sqlite3 3.37 was being used in either case. Needed to restart the terminal to pick up the link ( |
Just tried (the latest master) with macOS 10.15 Catalina, freshly installed on a 2015 Macbook Pro, Intel i5 dual core:
(caveat: I only synced a fraction of mainnet and then paused it, so the rescan part is a bit faster: 1ms on the 2015 machine vs 423ms on the 2019 machine) |
I'm not sure what to make of the benchmarking / results being posted here. I think in some cases not quite the right thing is being tested, or results are being mixed up. However the general case still seems to be that the brew libs are either the same speed, or much slower than the system libs. I haven't seen an argument for always prefering the brew libs, and in that case you're just rolling the dice for much worse performance, and ending up with #25724. Note that the benchmarking can also be performed without using Looking at the macOS sqlite system lib, it's pretty clear that it contains code that isn't in the open source sqlite. There are a number of additional symbols, including |
That's what I was testing. Concept ACK The presence of a Homebrew version doesn't mean the user intended it for Bitcoin. Relying on But the fact that the non-homebrew version sometimes is dramatically faster, is probably a good enough reason to prefer it. |
This seems to fix my performance issues on my m1 mac when running tests against bitcoind. This is on the official v23 release (36 seconds) This is on d216d71 (!5 seconds!) So this is a dramatic performance improvement for our test harness! In case anyone wants stack exchange reputation, consider answering this question: https://bitcoin.stackexchange.com/questions/113898/bitcoin-v23-is-10-times-slower-than-v22-on-macos-for-basic-regtest-tests |
Thanks for confirming this fixes the performance issues you've been seeing. While the release binaries still wont be "fixed", if/when this is merged, the situation for compiling locally / development should be much improved.
Good to know that they were using x86_64, so we can further rule out an x86_64 vs arm64 (M1) difference. The fact that developers are landing on the solution of "not upgrading", is another reason to fix this. |
ACK d216d71 I also observe a significant performance improvement with this. |
That is untrue. Besides #20527 description. one could refer #20498. Build docs implied that Bitcoin Core uses Homebrew's I'd say the opposite: this reversion is unjustified.
NACK from me. |
There is nothing in either of these threads that gives reasoning for why a brew installed sqlite should be preferred. #20498 just seems to be figuring out if macOS comes with a sqlite system library.
How so? This isn't being used in the release binaries. It's for developers/users self-compiling on macos. Self compilation / developer envinronments already come with lessened security assumptions, because your dependencies are coming from third party package managers, the OS, etc.
What you mean? Homebrew just compiles the unmodified sqlite source, there is nothing to "fix" there. Fixing this likely requires upstreaming changes to sqlite. If we actually had those changes, we could also be applying them in depends (and fixing this for releases).
So you suggest we leave this as-is, and just continually tell downstream projects / confused devs that to get reasonable performance in their developer environments, they have to compile differently, and avoid homebrews sqlite, even though our build system is setup to prefer it by default? Here's another instance of a project, this time BDK, running into this same problem: bitcoindevkit/bdk#749. |
Like that:
Our defaults must prioritize security, not performance. To avoid confusing, using of an Apple's library can be provided as an example in our docs. |
Can you clarify what you mean by security? I don't quite understand why we must avoid the system sqlite lib at all costs, while at the same time we are going to happily load any other number of apple shared libs (which are complete black boxes) at runtime (also true for release binaries).
In our release binaries, I agree. However, self-compilation on macOS, is almost always going to be a developer environment, which as I mentioned above, already comes with lessened security assumptions. In this case, from a security perspective, why is using Apples sqlite dylib, any worse than using homebrews? In both cases, you're using a precompiled library, provided by a third party. Are homebrews prebuilt libs even deterministic/reproducible? (I know you can tell brew to build from source, but 99.9% of users installing sqlite from brew are not doing that)? |
Possibly related: https://bonsaidb.io/blog/acid-on-apple/ |
Aha! I think this describes the problem exactly. Disabling |
It's quite possible that Apple is making assumptions about sqlite & the OS, that allows it to make these modifications / other improvements, that we likely cannot. In any case, we should still want this change, (assuming we could come up with a safe patchset for depends (for 25.0)), otherwise by picking brews sqlite, we would then still be choosing the worst of 3 available options, for performance, and continuing to cause confusion / issues downstream. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
After having an offline discussion with @fanquake, I agree with his points. Concept ACK. Our docs say:
But Homebrew can install its |
I agree with this point. Although most users won't self compile, I would not assume that most people who self compile are (experienced) developers.
I also agree with this. If (a rogue) Apple (employee) wanted to steal coins, there are probably more obscure corners of their black box library to put the backdoor in than SQlite.
It's actually worse that this, migrating a legacy wallet to descriptors takes more than ten minutes for me and leaves the wallet in an incorrect state. That said, this PR actually doesn't fix that problem for me, but it might for others. I do hope we can fix the real problem soon(tm), it seems @achow101 is optimistic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK d216d71
This seems like the best thing to do, assuming whatever apple does with their sqlite can't introduce any possibility of corrupt wallets or losing coins; which is unlikely considering native builds would have been using apple's sqlite for some time.
Confirmed macOS 10.14 (currently the minimum supported macOS version) includes a sqlite version greater than 3.7; for reference, it includes SQLite 3.24.0.
PR description is still incorrect in stating that the linked PR had no motivation.
I encountered the issue when working with BDK. OS: Mac OS Monterey 12.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if this is back ported on the effected version |
It can be merged into 24.x as-is (#26327), but for the other branches, someone will need to cherry-pick. |
…it is available" d216d71 Revert "build: Use Homebrew's sqlite package if it is available" (fanquake) Pull request description: Identical commit, taken as-is from #25985 ACKs for top commit: dergoegge: ACK d216d71 hebasto: ACK d216d71 Tree-SHA512: 8fe4cd20602e506f9cf4caa4d7b6c59142eccdd103cd6748f6e3e23464836d620b2d6142cb247a991fa8df5aa19678635d00ece5cf24d825ae6ca184c3bf7c48
This reverts ee7b84e from bitcoin#20527. This change was made without any rationale, maybe other than a brew installed version might be newer, and that's "better". However when building from source on macOS, it just results in drastically worse perofrmance, and results in issues / confusions like bitcoin#25724. Resolves the "build from source" portion of bitcoin#25724. Building from depends is still not ideal, however I have some other changes that might help improve things in that case. The difference in performance can be observed using the example from bitcoin#25724 (comment), but minified to only 10 descriptors. i.e: ```bash time src/bitcoin-cli createwallet speedy true time src/bitcoin-cli importdescriptors '[ {"desc":"raw(00145846369f3d6ba366d6f5a903fb5cf4dca3763c0e)#k9wh6v62","timestamp":"now"}, {"desc":"raw(001420800aabf13f3a4c4ce3ce4c66cecf1d17f21a6e)#6m0hlfh4","timestamp":"now"}, {"desc":"raw(0014c6bf9715e06d73ebf9b3b02d5cc48d24d8bbabc1)#wyavh36r","timestamp":"now"}, {"desc":"raw(00141ba7807b3f46af113beaea5c698428ce7138cd8a)#jctdsups","timestamp":"now"}, {"desc":"raw(00140c1bd27f10fff01b36ddf3c1febaa1acff19b080)#9s6nc3pk","timestamp":"now"}, {"desc":"raw(00141226e31987e4bc2e63c0ee12908f675e40464b20)#9pp7qm39","timestamp":"now"}, {"desc":"raw(0014f73f149f7503960a5e849c6ee7a8a8c336f631cb)#qtkxv9fc","timestamp":"now"}, {"desc":"raw(0014c8ccb4d81ffc769fc5fdd8d7eed69b0e0cae5749)#hn39qayv","timestamp":"now"}, {"desc":"raw(001498565aead2d67a22a6021d55210f2a917fc22169)#6ar3vwsx","timestamp":"now"}, {"desc":"raw(001403013248ac0cd9eabe176cad162cda2a19f771e1)#4m47mukd","timestamp":"now"} ]' ``` Running master, when building from souce and using brew installed sqlite, this takes ~3.4s. With this PR, the same operation takes ~0.3s. Github-Pull: bitcoin#25985 Rebased-From: d216d71
Did a cherry-pick for 23.x in #26333. |
This reverts ee7b84e from bitcoin#20527. This change was made without any rationale, maybe other than a brew installed version might be newer, and that's "better". However when building from source on macOS, it just results in drastically worse perofrmance, and results in issues / confusions like bitcoin#25724. Resolves the "build from source" portion of bitcoin#25724. Building from depends is still not ideal, however I have some other changes that might help improve things in that case. The difference in performance can be observed using the example from bitcoin#25724 (comment), but minified to only 10 descriptors. i.e: ```bash time src/bitcoin-cli createwallet speedy true time src/bitcoin-cli importdescriptors '[ {"desc":"raw(00145846369f3d6ba366d6f5a903fb5cf4dca3763c0e)#k9wh6v62","timestamp":"now"}, {"desc":"raw(001420800aabf13f3a4c4ce3ce4c66cecf1d17f21a6e)#6m0hlfh4","timestamp":"now"}, {"desc":"raw(0014c6bf9715e06d73ebf9b3b02d5cc48d24d8bbabc1)#wyavh36r","timestamp":"now"}, {"desc":"raw(00141ba7807b3f46af113beaea5c698428ce7138cd8a)#jctdsups","timestamp":"now"}, {"desc":"raw(00140c1bd27f10fff01b36ddf3c1febaa1acff19b080)#9s6nc3pk","timestamp":"now"}, {"desc":"raw(00141226e31987e4bc2e63c0ee12908f675e40464b20)#9pp7qm39","timestamp":"now"}, {"desc":"raw(0014f73f149f7503960a5e849c6ee7a8a8c336f631cb)#qtkxv9fc","timestamp":"now"}, {"desc":"raw(0014c8ccb4d81ffc769fc5fdd8d7eed69b0e0cae5749)#hn39qayv","timestamp":"now"}, {"desc":"raw(001498565aead2d67a22a6021d55210f2a917fc22169)#6ar3vwsx","timestamp":"now"}, {"desc":"raw(001403013248ac0cd9eabe176cad162cda2a19f771e1)#4m47mukd","timestamp":"now"} ]' ``` Running master, when building from souce and using brew installed sqlite, this takes ~3.4s. With this PR, the same operation takes ~0.3s. Github-Pull: bitcoin#25985 Rebased-From: d216d71
22.x in #26350. |
…it is available" d216d71 Revert "build: Use Homebrew's sqlite package if it is available" (fanquake) Pull request description: This reverts ee7b84e from bitcoin#20527. That change was made without any rationale, maybe other than, a brew installed version might be newer, and that's "better". However when building from source on macOS, it just results in drastically worse performance, and issues / confusion like bitcoin#25724. The difference in performance can be observed using the example from bitcoin#25724 (comment), but minified i.e: ```bash time src/bitcoin-cli createwallet speedy true time src/bitcoin-cli importdescriptors '[ {"desc":"raw(00145846369f3d6ba366d6f5a903fb5cf4dca3763c0e)#k9wh6v62","timestamp":"now"}, {"desc":"raw(001420800aabf13f3a4c4ce3ce4c66cecf1d17f21a6e)#6m0hlfh4","timestamp":"now"}, {"desc":"raw(0014c6bf9715e06d73ebf9b3b02d5cc48d24d8bbabc1)#wyavh36r","timestamp":"now"}, {"desc":"raw(00141ba7807b3f46af113beaea5c698428ce7138cd8a)#jctdsups","timestamp":"now"}, {"desc":"raw(00140c1bd27f10fff01b36ddf3c1febaa1acff19b080)#9s6nc3pk","timestamp":"now"}, {"desc":"raw(00141226e31987e4bc2e63c0ee12908f675e40464b20)#9pp7qm39","timestamp":"now"}, {"desc":"raw(0014f73f149f7503960a5e849c6ee7a8a8c336f631cb)#qtkxv9fc","timestamp":"now"}, {"desc":"raw(0014c8ccb4d81ffc769fc5fdd8d7eed69b0e0cae5749)#hn39qayv","timestamp":"now"}, {"desc":"raw(001498565aead2d67a22a6021d55210f2a917fc22169)#6ar3vwsx","timestamp":"now"}, {"desc":"raw(001403013248ac0cd9eabe176cad162cda2a19f771e1)#4m47mukd","timestamp":"now"} ]' ``` Running master, when building from souce and using brew installed sqlite, this takes ~3.4s. With this PR, the same operation takes ~0.3s. Resolves the "build from source" portion of bitcoin#25724. Building from depends is still not ideal, however I have some other changes that might help improve things in that case. Related performance issue reports: * bitcoindevkit/bdk#749 * https://bitcoin.stackexchange.com/questions/113898/bitcoin-v23-is-10-times-slower-than-v22-on-macos-for-basic-regtest-tests * bitcoin#25724 * bitcoin#25985 (comment) ACKs for top commit: achow101: ACK d216d71 jarolrod: ACK d216d71 hebasto: ACK d216d71, I have reviewed the code and it looks OK, I agree it can be merged. No conflicts with our build [docs](https://github.com/bitcoin/bitcoin/blob/d216d714aae36e6f1c95f82aef81a0be74dee2f3/doc/build-osx.md#descriptor-wallet-support). Tree-SHA512: 1bb4b44385b11fa9fe66edd7449278f9e47a6cc679b7111f9adf17db94c34e29c9cceafc917454e134420db40b24b56da29226af6f43e6dbeff822b79b77ed60
…it is available" 7698366 doc: remove brew install sqlite from macOS docs (fanquake) 419bdc5 Revert "build: Use Homebrew's sqlite package if it is available" (fanquake) Pull request description: Backport of #25985 to the 23.x branch. ACKs for top commit: hebasto: ACK 7698366, I have reviewed the code and it looks OK, I agree it can be merged. stickies-v: re-ACK 7698366 Tree-SHA512: 539f218b2895188111876b6a2035082ac642c89ef2e5055031bdc4563f690055012fcede396a5c87cf66e80ced796d62dd8d4394676fa6d22e01a581b29bb10b
…it is available" 63d2ee9 doc: remove brew install sqlite from macOS docs (fanquake) bf42d7d Revert "build: Use Homebrew's sqlite package if it is available" (fanquake) Pull request description: Backport of #25985 to the 22.x branch. ACKs for top commit: hebasto: ACK 63d2ee9, I have reviewed the code and it looks OK, I agree it can be merged. stickies-v: re-ACK [63d2ee9](63d2ee9) Tree-SHA512: 66738fc67df86db536a500fe253257976208b31773b891d6b6865b795ba4c933345febcc81773db159d3e1078810dbc8053fe63a7e9acad25b28d02dbf2687e8
This reverts ee7b84e from #20527.
That change was made without any rationale, maybe other than, a brew
installed version might be newer, and that's "better". However when
building from source on macOS, it just results in drastically worse
performance, and issues / confusion like #25724.
The difference in performance can be observed using the example from #25724 (comment),
but minified i.e:
Running master, when building from souce and using brew installed
sqlite, this takes ~3.4s. With this PR, the same operation takes ~0.3s.
Resolves the "build from source" portion of #25724. Building from
depends is still not ideal, however I have some other changes that might
help improve things in that case.
Related performance issue reports:
importdescriptors
RPC call very slow with release and source-built binaries, but fast for homebrew binaries #25724