FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Optimizations by vakrilov · Pull Request #207 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .csproj  (1) .ts  (7) .xml  (3) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions CrossPlatformModules.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<TypeScriptCompile Include="apps\tests\layouts\dock-layout-tests.ts" />
<TypeScriptCompile Include="apps\tests\pages\app.ts" />
<TypeScriptCompile Include="apps\tests\pages\file-load-test.ts" />
<TypeScriptCompile Include="apps\tests\pages\page-load-performance\start.ts" />
<TypeScriptCompile Include="apps\tests\pages\page-load-performance\test-big.ts" />
<TypeScriptCompile Include="apps\tests\pages\page-load-performance\test-small.ts" />
<TypeScriptCompile Include="apps\tests\pages\page12.ts" />
<TypeScriptCompile Include="apps\tests\layouts\absolute-layout-tests.ts" />
<TypeScriptCompile Include="apps\tests\layouts\layout-helper.ts" />
Expand Down Expand Up @@ -609,6 +612,13 @@
<Content Include="apps\TelerikNEXT\images\background.jpg" />
<Content Include="apps\template-settings\app.css" />
<Content Include="apps\tests\app\location-example.xml" />
<Content Include="apps\tests\pages\page-load-performance\start.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="apps\tests\pages\page-load-performance\test-big.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="apps\tests\pages\page-load-performance\test-small.xml" />
<Content Include="apps\tests\pages\page18.xml" />
<Content Include="apps\tests\ui\bindingContext_testPage.xml" />
<Content Include="apps\tests\ui\bindingContext_testPage1.xml" />
Expand Down
12 changes: 12 additions & 0 deletions apps/tests/pages/performance-test/start.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import frame = require("ui/frame");
import observable = require("data/observable");

declare function __startCPUProfiler(name: string);

export function navigate(args: observable.EventData) {
var tag = "" + args.object.get("tag");
__startCPUProfiler("xml-performance-" + tag);
frame.topmost().navigate({
moduleName: tag,
});
}
7 changes: 7 additions & 0 deletions apps/tests/pages/performance-test/start.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Page loaded="pageLoaded" >
<StackLayout>
<Button text="test small" tag="test-small" tap="navigate" />
<Button text="test big" tag="test-big" tap="navigate" />
<Button text="telerik next session" tag="telerik-next-session" tap="navigate" />
</StackLayout>
</Page>
7 changes: 7 additions & 0 deletions apps/tests/pages/performance-test/test-big.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import observable = require("data/observable");

declare function __stopCPUProfiler(name: string);

export function pageLoaded(args: observable.EventData) {
__stopCPUProfiler("xml-performance-test-big");
}
54 changes: 54 additions & 0 deletions apps/tests/pages/performance-test/test-big.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<Page loaded="pageLoaded" unloaded="pageUnloaded" backgroundColor="red">
<StackLayout>
<StackLayout>
<Button text="1button1" />
<Button text="1button2" />
<Button text="1button3" />
<Button text="1button4" />
<Button text="1button5" />
<Button text="1button6" />
<Button text="1button7" />
<Button text="1button8" />
</StackLayout>
<StackLayout>
<Button text="2button1" />
<Button text="2button2" />
<Button text="2button3" />
<Button text="2button4" />
<Button text="2button5" />
<Button text="2button6" />
<Button text="2button7" />
<Button text="2button8" />
</StackLayout>
<StackLayout>
<Button text="3button1" />
<Button text="3button2" />
<Button text="3button3" />
<Button text="3button4" />
<Button text="3button5" />
<Button text="3button6" />
<Button text="3button7" />
<Button text="3button8" />
</StackLayout>
<StackLayout>
<Button text="4button1" />
<Button text="4button2" />
<Button text="4button3" />
<Button text="4button4" />
<Button text="4button5" />
<Button text="4button6" />
<Button text="4button7" />
<Button text="4button8" />
</StackLayout>
<StackLayout>
<Button text="5button1" />
<Button text="5button2" />
<Button text="5button3" />
<Button text="5button4" />
<Button text="5button5" />
<Button text="5button6" />
<Button text="5button7" />
<Button text="5button8" />
</StackLayout>
</StackLayout>
</Page>
7 changes: 7 additions & 0 deletions apps/tests/pages/performance-test/test-small.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import observable = require("data/observable");

declare function __stopCPUProfiler(name: string);

export function pageLoaded(args: observable.EventData) {
__stopCPUProfiler("xml-performance-test-small");
}
12 changes: 12 additions & 0 deletions apps/tests/pages/performance-test/test-small.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Page loaded="pageLoaded" unloaded="pageUnloaded" backgroundColor="green">
<StackLayout>
<Button text="button1" />
<Button text="button2" />
<Button text="button3" />
<Button text="button4" />
<Button text="button5" />
<Button text="button6" />
<Button text="button7" />
<Button text="button8" />
</StackLayout>
</Page>
8 changes: 4 additions & 4 deletions ui/core/dependency-observable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ function validateRegisterParameters(name: string, ownerType: string) {
}

function getPropertyByNameAndType(name: string, owner: any): Property {
var baseClasses = types.getBaseClasses(owner);
var i;
var result;
var key;
for (i = 0; i < baseClasses.length; i++) {
key = generatePropertyKey(name, baseClasses[i]);
var classInfo = types.getClassInfo(owner);
while (classInfo) {
key = generatePropertyKey(name, classInfo.name);
result = propertyFromKey[key];
if (result) {
break;
}
classInfo = classInfo.baseClassInfo;
}
return result;
}
Expand Down
69 changes: 38 additions & 31 deletions ui/styling/style.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import imageSource = require("image-source");
import utils = require("utils/utils");

// key is the property id and value is Dictionary<string, StylePropertyChangedHandler>;
var _registeredHandlers = {};
var _registeredHandlers = Array<Object>();

// key is a className + property id and value is StylePropertyChangedHandler;
var _handlersCache = {};

// classes like Frame that does not need to handle styling properties.
var noStylingClasses = {};

Expand Down Expand Up @@ -292,48 +294,53 @@ export function registerHandler(property: dependencyObservable.Property,
handler: styling.stylers.StylePropertyChangedHandler,
className?: string) {
var realClassName = className ? className : "default";
if (_registeredHandlers.hasOwnProperty(property.id + "")) {
_registeredHandlers[property.id][realClassName] = handler;
}
else {
var handlerRecord = {};
handlerRecord[realClassName] = handler;

var handlerRecord = _registeredHandlers[property.id];
if (!handlerRecord) {
handlerRecord = {};
_registeredHandlers[property.id] = handlerRecord;
}

handlerRecord[realClassName] = handler;
}

export function registerNoStylingClass(className) {
noStylingClasses[className] = 1;
}

export function getHandler(property: dependencyObservable.Property, view: view.View): styling.stylers.StylePropertyChangedHandler {
var classNames = types.getBaseClasses(view);
// adding default as last class name if no other class is found default handler will be used
classNames.push("default");
if (_handlersCache.hasOwnProperty(classNames[0] + property.id)) {
return _handlersCache[classNames[0] + property.id];
return getHandlerInternal(property.id, types.getClassInfo(view));
}

function getHandlerInternal(propertyId: number, classInfo: types.ClassInfo): styling.stylers.StylePropertyChangedHandler {
var className = classInfo ? classInfo.name : "default";
var handlerKey = className + propertyId;

// try the cache first
var result = _handlersCache[handlerKey];
if (types.isDefined(result)) {
return result;
}

var propertyHandlers = _registeredHandlers[propertyId];
if (noStylingClasses.hasOwnProperty(className) || !propertyHandlers) {
// Reached 'no-styling' class or no property handlers are registered for this proeprtyID
result = null;
}
else if (propertyHandlers.hasOwnProperty(className)) {
// Found handler for this class
result = propertyHandlers[className];
}
else if (classInfo) {
// Check the base class
result = getHandlerInternal(propertyId, classInfo.baseClassInfo);
}
else {
var i;
var propertyHandlers;
var handler;
propertyHandlers = _registeredHandlers[property.id];
for (i = 0; i < classNames.length; i++) {
if (propertyHandlers) {
var loopClassName = classNames[i];
if (noStylingClasses.hasOwnProperty(loopClassName)) {
_handlersCache[loopClassName + property.id] = null;
return null;
}
if (propertyHandlers.hasOwnProperty(loopClassName)) {
handler = propertyHandlers[loopClassName];
_handlersCache[loopClassName + property.id] = handler;
return handler;
}
}
}
result = null;
}
return null;

_handlersCache[handlerKey] = result;
return result;
}

// Property registration
Expand Down
22 changes: 22 additions & 0 deletions utils/types.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,26 @@
* Return an array of strings with the name of all classes.
*/
export function getBaseClasses(object): Array<string>;

/**
* A function that gets the ClassInfo for an object.
* @param object The object for which the ClassInfo will be get.
* Returns a ClassInfo for the object.
*/
export function getClassInfo(object: Object): ClassInfo;

/**
* A Class holding information about a class
*/
export class ClassInfo {
/**
* Gets the name of the class.
*/
name: string;

/**
* Gets the ClassInfo for the base class of the current info.
*/
baseClassInfo: ClassInfo;
}
}
72 changes: 58 additions & 14 deletions utils/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,71 @@ export function verifyCallback(value: any) {
}
}

var classInfosMap = new Map<Function, ClassInfo>();
var funcNameRegex = /function (.{1,})\(/;
export function getClass(object): string {
var results = (funcNameRegex).exec((object).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
export function getClass(object: Object): string {
return getClassInfo(object).name;
}

export function getClassInfo(object: Object): ClassInfo {
var constructor = object.constructor;

var result = classInfosMap.get(constructor);
if (!result) {
result = new ClassInfo(constructor);
classInfosMap.set(constructor, result);
}

return result;
}

export function getBaseClasses(object): Array<string> {
var baseProto = object.__proto__;
var result = [];
result.push(getClass(object));

while (baseProto !== Object.prototype) {
var baseProtoString = baseProto.toString();
// while extending some classes for platform specific versions results in duplicate class types in hierarchy
if (result.indexOf(baseProtoString) === -1) {
result.push(baseProtoString);
var info = getClassInfo(object);
while (info) {
result.push(info.name);
info = info.baseClassInfo;
}
return result;
}

export class ClassInfo {
private _typeCosntructor: Function;
private _name: string;
private _baseClassInfo: ClassInfo;

constructor(typeCosntructor: Function) {
this._typeCosntructor = typeCosntructor;
}

get name(): string {
if (!this._name) {
var results = (funcNameRegex).exec(this._typeCosntructor.toString());
this._name = (results && results.length > 1) ? results[1] : "";
}
baseProto = baseProto.__proto__;

return this._name;
}

result.push("Object");
get baseClassInfo(): ClassInfo {
if (isUndefined(this._baseClassInfo)) {
this._baseClassInfo = ClassInfo._getBase(this);

return result;
// While extending some classes for platform specific versions results in duplicate class types in hierarchy.
if (this._baseClassInfo && this._baseClassInfo.name === this.name) {
this._baseClassInfo = ClassInfo._getBase(this._baseClassInfo);
}
}

return this._baseClassInfo;
}

private static _getBase(info: ClassInfo): ClassInfo {
var result = null;
var constructorProto = info._typeCosntructor.prototype;
if (constructorProto.__proto__) {
result = getClassInfo(constructorProto.__proto__);
}
return result;
}
}

Back | FazBrowse Home | New Git URL