Tag - object
2014, Sunday May 18
By A.Bouchez on 2014, Sunday May 18, 16:05 - mORMot Framework
We have just added a new "25
- JSON performance" sample to benchmark JSON process, using well most known
A new fight
mORMot vs SuperObject/XSuperObject/dwsJSON/DBXJSON
On mORMot side, it covers
TDocVariant, late binding,
TSQLTable, ORM, record access, BSON...
We tried to face several scenarios:
- parse/access/write iteration over a small JSON document,
- read of deeply nested 680 KB JSON (here mORMot is slower than
- read of one 180 MB JSON file (with on-the-fly adaptation to fit a record
- named access to all rows and columns of a 1 MB JSON table, extracted from a
SQL request (with comparison with our ORM performance).
On average and in details, mORMot is the fastest in almost all
scenarios (with an amazing performance for table/ORM processing),
dwsJSON performs very well (better than SuperObject), and
DBXJSON is the slowest (by far, but XE6 version is faster than
2014, Friday February 28
By A.Bouchez on 2014, Friday February 28, 22:12 - mORMot Framework
One of the main features you may miss when discovering NoSQL ("Not-Only
SQL"?) databases, coming from a RDBMS background, is ACID.
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties
that guarantee that database transactions are processed reliably. In the
context of databases, a single logical operation on the data is called a
transaction. For example, a transfer of funds from one bank account to another,
even involving multiple changes such as debiting one account and crediting
another, is a single transaction. (Wikipedia)
But are there any ACID
Please ensure you read the Martin Fowler
introduction about NoSQL databases.
And the corresponding
First of all, we can distinguish two types of NoSQL databases:
- Aggregate-oriented databases;
- Graph-oriented databases (e.g. Neo4J).
By design, most Graph-oriented databases are ACID!
This is a first good point.
Then, what about the other type?
In Aggregate-oriented databases, we can identify three sub-types:
- Document-based NoSQL databases (e.g.
- Key/Value NoSQL databases (e.g. Redis);
- Column family NoSQL databases (e.g. Cassandra).
Whatever document/key/column oriented they are, they all use some kind of
It may be schema-less, blob-stored, column-driven, but it is always some set of
values bound together to be persisted.
This set of values define a particular state of one entity, in a given
Which we may call Aggregate.
2014, Tuesday February 25
By A.Bouchez on 2014, Tuesday February 25, 18:41 - mORMot Framework
With revision 1.18 of the framework, we just introduced two new custom types
TDocVariant kind of
TBSONVariant kind of
The second custom type (which handles MongoDB-specific extensions -
ObjectID or other specific types like dates or binary) will
be presented later, when dealing with MongoDB support in
mORMot, together with the BSON kind of content. BSON /
MongoDB support is implemented in the
We will now focus on
TDocVariant itself, which is a generic
container of JSON-like objects or arrays.
This custom variant type is implemented in
SynCommons.pas unit, so
is ready to be used everywhere in your code, even without any link to the
mORMot ORM kernel, or MongoDB.
TDocVariant implements a custom variant type which can be used
to store any JSON/BSON document-based content, i.e. either:
- Name/value pairs, for object-oriented documents;
- An array of values (including nested documents), for array-oriented
- Any combination of the two, by nesting
Here are the main features of this custom variant type:
- DOM approach of any object or array documents;
- Perfect storage for dynamic value-objects content, with a
schema-less approach (as you may be used to in scripting languages
- Allow nested documents, with no depth limitation but the available
- Assignment can be either per-value (default, safest but slower
when containing a lot of nested data), or per-reference (immediate
- Very fast JSON serialization / un-serialization with support of
MongoDB-like extended syntax;
- Access to properties in code, via late-binding (including almost no speed
penalty due to our VCL hack as already detailed);
- Direct access to the internal variant names and values
arrays from code, by trans-typing into a
- Instance life-time is managed by the compiler (like any other
variant type), without the need to use
- Optimized to use as little memory and CPU resource as possible (in contrast
to most other libraries, it does not allocate one
per node, but rely on pre-allocated arrays);
- Opened to extension of any content storage - for instance, it will
perfectly integrate with BSON serialization and custom MongoDB types
(ObjectID, RegEx...), to be used in conjunction with MongoDB
- Perfectly integrated with our Dynamic
array wrapper and its JSON serialization as with the
- Designed to work with our mORMot ORM: any
instance containing such
variant custom types as published
properties will be recognized by the ORM core, and work as expected with any
database back-end (storing the content as JSON in a TEXT column);
- Designed to work with our mORMot SOA: any
service is able to consume or publish such kind of content, as
variant kind of parameters;
- Fully integrated with the Delphi IDE: any
will be displayed as JSON in the IDE debugger, making it very convenient to
To create instances of such
variant, you can use some
_Obj() _ObjFast() global functions to create a
variant object document;
_Arr() _ArrFast() global functions to create a
variant array document;
_Json() _JsonFast() _JsonFmt() _JsonFastFmt() global functions
to create any
variant object or array document
from JSON, supplied either with standard or MongoDB-extended
2013, Tuesday December 10
By A.Bouchez on 2013, Tuesday December 10, 22:02 - mORMot Framework
In Delphi, the
record has some nice advantages:
record are value objects, i.e. accessed by value, not by
reference - this can be very convenient, e.g. when defining a Domain-Driven
record can contain any other
dynamic array, so are very convenient to work with (no need to define
sub-classes or lists);
record variables can be allocated on stack, so won't solicit
the global heap;
record instances automatically freed by the compiler when they
come out of scope, so you won't need to write any
record values are therefore a must-have for a
framework like mORMot.
In recent commits, this JSON serialization of
record has been
In particular, we introduced JSON serialization via a new text-based
2013, Wednesday October 9
By A.Bouchez on 2013, Wednesday October 9, 08:07 - Pascal Programing
Yes, I know this article title is a huge moment of trolling for most Delphi
object could be legend... - wait for it - ... dary!
You perhaps already noticed by several blog posts
here that I still like the good old (and deprecated)
type, in addition to the common heap-allocated
record with methods does not match the object-oriented
object, since it does not feature inheritance.
When you take a look at modern strongly-typed languages, targeting
concurrent programming (you know, multi-thread/multi-core execution), you will
see that the objects may be allocated in several ways, to facilitate execution
The Rust language for instance is
pretty interesting. It has optional task-local Garbage Collection and safe
pointer types with region analysis.
To some extent, it is very similar to what
object allows in the
Delphi world, and why I'm still using/loving it!
2013, Saturday May 11
By A.Bouchez on 2013, Saturday May 11, 10:59 - Pascal Programing
When I first read the
technical white paper covering all of the language changes in XE4 for mobile
development (tied to the new ARM LLVM-based Delphi compiler), I have to
confess I was pretty much confused.
Two great mORMot users
just asked for XE4/iOS support of mORMot.
Win32/Win64 support for XE4 will be done as soon as we got a copy of
I suspect the code already works, since it was working as expected with XE3,
and we rely on our own set of low-level functions for most internal work.
But iOS-targetting is more complex, due to the NextGen compiler, mainly.
2013, Thursday March 7
By A.Bouchez on 2013, Thursday March 7, 17:19 - mORMot Framework
I'm happy to announce that mORMot units are now compiling and working great in 64
bit mode, under Windows.
Need a Delphi XE2/XE3 compiler, of course!
ORM and services are now available in Win64, on both client and
Low-level x64 assembler stubs have been created, tested and
UI part is also available... that is grid display, reporting (with pdf
export and display anti-aliasing), ribbon auto-generation,
SynTaskDialog, i18n... the main SynFile demo just works
Overall impression is very positive, and speed is comparable to 32 bit
version (only 10-15% slower).
Speed decrease seems to be mostly due to doubled pointer size, and some less
optimized part of the official Delphi RTL.
But since mORMot core uses its own set of functions (e.g. for
JSON serialization, RTTI support or interface calls or stubbing), we were able
to release the whole 64 bit power of your hardware.
Delphi 64 bit compiler sounds stable and efficient. Even when working at low
level, with assembler stubs.
Generated code sounds more optimized than the one emitted by
FreePascalCompiler - and RTL is very close to 32 bit mode.
Overall, VCL conversion worked as easily than a simple re-build.
Embarcadero's people did a great job for VCL Win64 support, here!
2012, Sunday May 20
By A.Bouchez on 2012, Sunday May 20, 09:47 - Pascal Programing
In a Stack Overflow
question, someone asked about some nested procedure call he found out. That
is, a procedure inside another procedure.
He found out this coding style to be messy, which sounds like a reasonable
opinion. But his alternative proposal of putting the internal procedure outside
the main one, i.e. making it global, is IMHO even worse.
In some case, a private
class, or even
object with methods is an handy and maintainable implementation
2012, Friday April 13
By A.Bouchez on 2012, Friday April 13, 12:07 - mORMot Framework
By default, our mORMot framework is able to serialize any class
into a true JSON object.
published properties will be written as JSON object
In some cases, it may be handy to have a custom serialization, for instance
if you want to manage some third-party classes, or to adapt the serialization
scheme to a particular purpose, at runtime.
2012, Thursday April 12
By A.Bouchez on 2012, Thursday April 12, 20:33 - mORMot Framework
One nice feature of the
TDynArray wrapper and its associated
methods, as defined and used in our framework, is the ability to serialize
any dynamic array as JSON content.
By default, only "standard" dynamic arrays (like
TIntegerDynArray) are serialized as true JSON array: other not
known kind of arrays are serialized as binary content, within a Base64
This is a very efficient solution for a pure Delphi application, since it
will be fast and always works, but won't be easy to deal with from an AJAX
Applications can now supply a custom JSON serialization for any other
dynamic array, via the
Two callbacks are to be supplied for a dynamic array type information, in order
to handle proper serialization and un-serialization of the JSON array.
2012, Wednesday February 29
By A.Bouchez on 2012, Wednesday February 29, 23:45 - Pascal Programing
No, interface(-book) is not another social network, sorry.
In Delphi OOP model, an interface defines a type that comprises
abstract virtual methods.
The short, easy definition is that an interface is a declaration of
functionality without an implementation of that functionality. It defines
"what" is available, not "how" it is made available. This is the so called
"abstraction" benefit of interfaces (there are another benefits, like
orthogonality of interfaces to classes, but we'll see it later).
In its upcoming 1.16 revision, our mORMot framework is able to use interface
for its service definition.
So we'll discuss and introduce this gem available in all modern languages -
including Delphi: interfaces.
2011, Thursday December 8
By A.Bouchez on 2011, Thursday December 8, 10:09 - Pascal Programing
Among all trolling subject in forums, you'll find out the
great Garbage Collection theme.
Fashion languages rely on it. At the core of the .Net and Java framework,
find a Garbage Collector. New developers, just released from schools, do
learn about handling memory only in theory, and just can't understand how is
memory allocated - we all have seen such rookies involved in Delphi code
maintenance, leaking memory as much as they type. In fact, most of them did not
understood how a computer works. I warned you this will be a trolling
And, in Delphi, there is no such collector. We handle memory in
- Creating static variables - e.g. on the stack, inside a
- Creating objects with
class instances allocated on heap - in
at least three ways: with a
try..finally Free block, with a
TComponent ownership model in the VCL, or by using
interface (which creates an hidden
- Creating reference-counted variables, i.e.
variant kind of
It is a bit complex, but it is also deadly powerful. You have several memory
allocation models at hand, which can be very handy if you want to tune your
performance and let program scale. Just like manual recycling at home will save
the planet. Some programmers will tell you that it's a waste of cell brain,
typing and time. Linux kernel gurus would not say so, I'm afraid.
Then came the big Apple company, which presented its new ARC model
(introduced in Mac OS X 10.7 Lion) as a huge benefit for
Objective-C in comparison with the Garbage Collection model. And
let's face it: this ARC just sounds like the Delphi memory model.
2011, Tuesday December 6
By A.Bouchez on 2011, Tuesday December 6, 22:08 - mORMot Framework
In mORMot, all the methods available to handle many-to-many
ManySelect, DestGetJoined...) are used to
retrieve the relations between tables from the pivot table point of view. This
saves bandwidth, and can be used in most simple cases, but it is not the only
way to perform requests on many-to-many relationships. And you may have several
TSQLRecordMany instances in the same main record - in this case,
those methods won't help you.
It is very common, in the SQL world, to create a JOINed request at the main
"Source" table level, and combine records from two or more tables in a
database. It creates a set that can be saved as a table or used as is. A JOIN
is a means for combining fields from two or more tables by using values common
to each. Writing such JOINed statements is not so easy by hand, especially
because you'll have to work with several tables, and have to specify the exact
fields to be retrieved; if you have several pivot tables, it may start to be a
Let's see how our ORM will handle it.
2011, Sunday November 27
By A.Bouchez on 2011, Sunday November 27, 23:39 - Pascal Programing
Delphi is sometimes assimilated to a RAD product - and this is a marketing
label - but IMHO Delphi is much more than RAD.
With Delphi, you can make very serious and clean programming.
Including SOLID style of coding.
The acronym SOLID is derived from the following OOP principles (quoted from
- Single responsibility principle: the notion that an object should
have only a single responsibility;
- Open/closed principle: the notion that “software entities ...
should be open for extension, but closed for modification”;
- Liskov substitution principle: the notion that “objects in a
program should be replaceable with instances of their subtypes without altering
the correctness of that program” - also named as "design by
- Interface segregation principle: the notion that “many client
specific interfaces are better than one general purpose interface.”;
- Dependency inversion principle: the notion that one should “Depend
upon Abstractions. Do not depend upon concretions.”. Dependency
injection is one method of following this principle.
If you have some programming skills, those principles are general statements
you may already found out by yourself. If you start doing serious
object-oriented coding, those principles are best-practice guidelines you would
They certainly help to fight the three main code weaknesses:
- Rigidity – Hard to change something because every change affects
too many other parts of the system;
- Fragility – When you make a change, unexpected parts of the system
- Immobility – Hard to reuse in another application because it
cannot be disentangled from the current application.
2011, Friday May 20
By A.Bouchez on 2011, Friday May 20, 21:02 - Pascal Programing
How to make your software run fast, especially in a
We tried to remove the Memory Manager scaling problems in our SynScaleMM. It worked as expected in a
multi-threaded server environment. Scaling is much better than FastMM4, for
some critical tests. But it's not ready for production yet...
To be honest, the Memory Manager is perhaps not the bigger bottleneck
in Multi-Threaded applications.
Here are some (not dogmatic, just from experiment and knowledge of low-level
Delphi RTL) advice if you want to write FAST multi-threaded application in
2011, Saturday March 12
By A.Bouchez on 2011, Saturday March 12, 12:55 - Pascal Programing
The SynCommons unit has been enhanced:
- new low-level RTTI functions for handling record types:
RecordSave, RecordSaveLength, RecordLoad;
TDynArray object, which is a wrapper around any dynamic
TDynArray, you can access any dynamic array (like
TIntegerDynArray = array of integer) using
properties and methods, e.g.
Count, Add, Insert, Delete, Clear, IndexOf,
Find, Sort and some new methods like
SaveTo which allow fast binary serialization
of any dynamic array, even containing strings or records - a
CreateOrderedIndex method is also available to create individual
index according to the dynamic array content. You can also serialize the array
content into JSON, if you wish.
What I like with dynamic arrays is that they are reference-counted, don't
Create/try..finally...Free code, and are well handled by
the Delphi compiler.
They are no replacement to a
TCollection nor a
TList (which are the standard and efficient way of storing
class instances), but they are very handy way of having a list of content or a
dictionary at hand, with no class nor properties definition.
You can look at them like Python's list, tuples (via records handling) and
Find method), in pure Delphi. Our new methods
(about searching and serialization) allow most usage of those script-level
structures in your Delphi code.
2010, Thursday October 28
By A.Bouchez on 2010, Thursday October 28, 20:37 - mORMot Framework
Extracted from wikipedia, here is
a definition of 'many to many' relationships in regular database
In systems analysis, a many-to-many relationship is a type of cardinality
that refers to the relationship between two entities (see also
Entity-Relationship Model) A and B in which A may contain a parent row for
which there are many children in B and vice versa. For instance, think of A as
Authors, and B as Books. An Author can write several Books, and a Book can be
written by several Authors. Because most database management systems only
support one-to-many relationships, it is necessary to implement such
relationships physically via a third and fourth junction table, say, AB with
two one-to-many relationships A -> AB and B -> AB. In this case the
logical primary key for AB is formed from the two foreign keys (i.e. copies of
the primary keys of A and B).
In our SQLite3 framework, we just created a dedicated class for handling such
"many to many" relationships.
2010, Friday August 6
By A.Bouchez on 2010, Friday August 6, 11:31 - Pascal Programing
In a recent thread in the Embarcadero
Discussion Forums, Vedran Vuk posted some questions about object
His purpose was to use object instead of class to improve speed and memory
I do use classes. I just want to use objects on smaller classes that
don't really need initialization or RTTI. Plus, I can directly operate on it
like a record with no need for constructors and it can be sealed and has
inheritance. Every byte matters in this case.
Rudy posted on the EMB forum that
The "object" type is deprecated. As was said, it mainly exists for
compatibility with old Turbo Pascal. That is why it is not documented very
well. It's use is not promoted.
I have the same requirement sometimes, for example for our framework or for
I do like such plain-old object type, and don't want to see this object
feature marked as deprecated in future EMB versions.