Baigudin Software avatar
Baigudin Software logo
ru region
en region


BOOS Core has been released as version 2.1

The new release of BOOS Core has gotten ARM architecture with instruction set version 5, some independent algorithms of any compilers, root interface for all interfaces, and many tiny aspects, which were implemented in it.

Optimization of source code

"The program would have been working if you had held your breath and had not been breathing". It is a good statement, but if a program is working slowly, or it is not flexible, what will we do? Yes, we need to optimize, to debug, and to test it again. Clearly, acceptable compromise between usability and performance is not being found so easily. Just, we should be thinking about it while designing time, and future updating will be easy.

Elements fetching optimization

Results of searching do not cache. This is the main rule which  you need to remember. Every time, when we inquire to find elements of tree, the library scans that tree again. Therefore, the searching is faster if a branch is shorter.

The best way is to save a searching result to local variable:

// It is bad
$node $document->find('a')->addClass('link');
// It is good

We can use a chain of calls:

// It is good too

We can truncate a tree to "div.article":

// It is bad
$document->find('div.article h2');
$document->find('div.article a');
// It is good
$node $document->find('div.article');

Indexing of elements

An object of ElementNode class can get a string index, which is called a key, by using key method of the library. The key will be associated with a sequence number of the element in new created list of elements. Thus, we can get an access to the element of a list by its key.

use DomBuilder\Element as Element;
// Create document
$document Element::create()
// Create empty list
$list Element::newList();
// Add elements to list
$list->pushElement::create('h1')->html('My header')->key('header') );
$list->pushElement::create('p')->html('My text') )->key('text');
// Add elements of list to document by its keys
insert$list->get('header') )
after$list->get('text') );
// Output document
echo Element::getDocument($document);

We want to mark that you can add a key for an element when you have created it, or you can add a key for a list. If you call key method for ElementList class, the key will be added for last added element to the list.

Note: The library does not monitor that a key is one and only. It is needed in keys only for associating an element in elements list. Therefore, if a list has greater than one element with equal keys, it returns the last added element with that key to its.

We have considered a few simple ways to make applications faster and more intelligible for future supporting. In next article, we will continue to talk about optimizations and tell you about multi-language supporting in range of the library. 

To the previous article

To the articles list

To the next article