
Show HN: I Ported LevelDB to Universal Windows Platform - maxpert
https://github.com/maxpert/LevelDBWinRT
======
flohofwoe
This nicely demonstrates the main design blunder of the Universal Windows
Platform: introducing an incompatible dialect of C++ (called C++/CX, formerly
known as C++/CLI, formerly known as Managed C++).

I really wonder why Microsoft had to invent their own, incompatible C++
dialect when projects like emscripten can cross-compile perfectly standard C++
to Javascript, which is a much more exotic compile target than the .NET
runtime.

~~~
notreallyright
C++/CX is a convenience syntax for creating and working with types in the
windows runtime. In all of the talks given by Herb Suttor, a MS employee and
active member of the C++ standards committee, he says to use it at ABI
boundaries and use standard C++ everywhere else.

If that's not good enough for you there is also Mondern C++ by Kenny Kerr
which is a C++1x projection of the windows runtime.

~~~
flohofwoe
Yes, I think that makes the most sense to keep C++/CX language constructs
isolated to only a few places that need to talk to the UWP APIs, similar to
how one would contain Objective-C(++) when talking to OSX APIs to only a few
places.

------
kozukumi
Have you written about how you found the process? The good and bad things,
etc. With UWP being so new and untested it is hard to find much information on
porting an already established codebase to the platform. How is performance,
etc?

~~~
maxpert
Hey thanks for your interest, I have been working on UWP for quite a while
now; it has been both good and bad.

My biggest gripe right now is no good DB support (SQLite requires an extension
and that two is not enough; you have next to nothing ORMs and well EF7 is
still RC). In today's world I can't image an App not finding database as a
useful platform feature, Android/iOS have builtin DB support and they prove
the fact how important DB support could be. I just don't understand what were
people smoking when they made a decision to not include a DB framework in UWP.

XAML framework has it's own bugs, caveats, and yes there is next to nothing
material available to help you. They have improved a-lot with x:Bind but then
you find bugs like this [https://social.msdn.microsoft.com/Forums/en-
US/c2bde144-47ae...](https://social.msdn.microsoft.com/Forums/en-
US/c2bde144-47ae-4eb9-817f-1f434caa05f5/uwpcxaml-compiled-binding-xbind-cause-
memory-leaks?forum=wpdevelop) over which you would spend a whole week and then
say "AH FUCK IT; use Binding instead".

Performance is good with .NET native but not as good as you would picture a
native code to be. I have seen Java blowing my mind just with JIT. Personally
I felt Microsoft has done good job of performance on PC since they have
mastered the x86/x64, but ARM feels a little slow to me.

I personally strongly feel (coming from WP 8.1 platform) that UWP is better
but it feels like an RC; it has broken ends, missing good documentation (hell
wrong documentation sometimes), and next to nothing opensource community
support. One of my colleagues clearly said that if he has to choose to work on
another UWP project he would choose to not work on it.

------
roryisok
Any chance of a version for WinJS? The only javascript based database
available to both Windows Phone and Windows Store apps is SQLite, and it's
seriously buggy

~~~
WorldMaker
You should be able to use this like any other WinRT component in WinJS.

SQLite support should hopefully get better now that it has been added to the
platform SDK.

Also, have you tried PouchDB yet? I've gotten some good results from it.

~~~
maxpert
When was it added to Platform SDK? I am using VS 2015 Update 1.

~~~
WorldMaker
Looks like Platform SDK 10586:

[https://blogs.windows.com/buildingapps/2015/12/03/windows-10...](https://blogs.windows.com/buildingapps/2015/12/03/windows-10-build-10586-sdk-
breakdown/)

Edit to add: Believe this is the same SDK included in VS 2015 Update 1.

------
Const-me
But why? Windows already has ESENT.

That embedded NoSQL database engine is developed and supported by Microsoft.
Available since windows 2000, on the phones since 8.0.

The functionality is much more. While you surely can use it as a key-value
store, if you need more there’re secondary indices, column schema, multivalued
columns, version columns, auto-increment columns, sparse indices,
transactions…

~~~
maxpert
Can you point me any tutorial or post that does a walk through on how to use
ESENT on UWP applications?

EDIT: I found ManagedESENT and yes there is a way to do it in UWP apps too but
API seems like it's from stone-age example:

Api.JetCreateInstance(out instance, "instance");

Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.CircularLog, 1,
null);

Api.JetInit(ref instance);

~~~
Const-me
As for the API, I agree that on UWP, it’s too low level.

For desktop platforms, I’ve built my own ORM on top of that:
[https://esentserialize.codeplex.com/](https://esentserialize.codeplex.com/)
However, I’m too lazy to port that on Windows Store unless I’m paid for that:
the main problem isn’t ESENT, it’s the reflection that I use extensively for
serializing/deserialising those records/fields.

Edit: but if you only need key-value storage with both keys and values being
blob of bytes, the complete implementation on top of Managed ESENT will be
like four pages of C# code.

The main complexity in ESENT isn’t DB initialization. For initialization, you
copy-paste DB initialization code from PersistentDictionary or some other
sample and forget about that (until much later when you'll be optimizing the
DB performance). The hard parts are column schema, index schema, queries,
schema upgrades, and also on servers it’s concurrency.

