我们的一个页面很重.为了减少我们的观察者数量并加速角度摘要周期,我们使用了大量的On-Time-Binding语法::
.我们还使用angular-bind-notifier来避免对此页面上的表达式进行不必要的监视.
这种策略使我们能够大大减少角度消化周期.
但是这种策略有一个缺点:它在成功评估后使用$$postDigest
(postDigestQueue
)unwatch
表达式.
所以呢 ?
在摘要的最后,角度将穿过postDigestQueue
.由于我们使用了大量的On-Time-Binding表达式,因此我们postDigestQueue
可以增长到超过10万个排队任务.
问题是angular使用以下代码循环队列:
while (postDigestQueue.length) {
try {
postDigestQueue.shift()();
} catch (e) {
$exceptionHandler(e);
}
}
Run Code Online (Sandbox Code Playgroud)
shift方法删除零点索引处的元素并将连续索引处的值向下移动,然后返回删除的值.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
是的,Array.prototype.shift()
当阵列中有很多元素时,这是一个非常昂贵的调用.
由于这个原因,我们的摘要周期有时会超过20秒.
当我们使用以下代码更改以前的代码时,它会更快:
for (var i = 0; i < postDigestQueue.length; i++) {
try {
postDigestQueue[i]();
} catch (e) {
$exceptionHandler(e);
}
}
postDigestQueue.length = 0;
Run Code Online (Sandbox Code Playgroud)
有没有理由他们这样做?我们不应该使用那么多的一次性绑定吗?
我可以看到一个原因:如果一个任务在队列中添加了一个需要任务.有可能吗?($$postDigest
是一个私人队列)答案是使用pop
而不是shift
如果执行顺序不重要,但是它?
编辑:顺序似乎很重要,因为postDigestQueue
它与动画一起使用. …
7个月前,我们开始学习C#和WPF,并且,作为所有想要进行图像处理的新手,我们遇到了这个问题:
为什么有Bitmap和BitmapSource?每个有什么好处?
在我们的项目中,我们必须从数据生成位图.速度对我们来说非常重要.
我们从Bitmap开始,因为它更容易(特别是方法:get/setpixel),有很多例子.但后来我们在WPF中发现了转换问题以打印Bitmap.
所以我们尝试使用BitmapSource,由于不同的像素格式,这并不容易.但我们最终取得了成功.
我们比较了每一代的速度.使用SetPixel(Bitmap)远比使用字节数组(BitmapSource)慢,但使用字节数组意味着并发症:步幅,像素格式......
所以我们确定选择了BitmapSource.但后来我们想要序列化一些BitmapSource.BitmapSource不可序列化.因此,使用[OnSerializing] [OnDeserialized],我们在Bitmap中转换了BitmapSource(可序列化).
我们的结论是:
位图优势:
BitmapSource的优点:
你看到其他一些观点吗?
为了说明和我们这样的新手,我们需要一些有用的方法:
public static System.Windows.Media.Imaging.BitmapSource BitmapToBitmapSource(System.Drawing.Bitmap source)
{
using (MemoryStream memory = new MemoryStream())
{
source.Save(memory, ImageFormat.Png);
memory.Position = 0;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
public static System.Drawing.Bitmap BitmapFromSource(BitmapSource source)
{
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new PngBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(source));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
// return …
Run Code Online (Sandbox Code Playgroud) 我希望用来SqlDependency
在使用数据库的其他应用程序更改某些数据时收到通知.
public class DatabaseChangesNotification : IDisposable
{
private static string chaineDeConnexion = ConfigurationManager.ConnectionStrings["TransfertContext"].ConnectionString;
private static readonly Lazy<DatabaseChangesNotification> _instance = new Lazy<DatabaseChangesNotification>(() => new DatabaseChangesNotification());
private DatabaseChangesNotification()
{
System.Diagnostics.Trace.WriteLine("--- SqlDependency START ---");
SqlDependency.Start(chaineDeConnexion);
}
public void Dispose()
{
System.Diagnostics.Trace.WriteLine("--- SqlDependency STOP ---");
SqlDependency.Stop(chaineDeConnexion);
}
public static DatabaseChangesNotification Instance
{
get
{
return _instance.Value;
}
}
public void AbonnerNotification(string requete, OnChangeEventHandler eventhandler)
{
using (SqlConnection connection = new SqlConnection(chaineDeConnexion))
{
using (SqlCommand command = new SqlCommand(requete, connection) { Notification = …
Run Code Online (Sandbox Code Playgroud) 目的
我有一个接口TypeScript:
interface IInterface{
id: number;
name: string;
}
Run Code Online (Sandbox Code Playgroud)
我有一些方法可以输入属性的名称(字符串).
例如:
var methodX = ( property: string, object: any ) => {
// use object[property]
};
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我打电话时methodX
,我必须在字符串中写入属性名称.
例如: methodX("name", objectX);
objectX实现IInterface
但是,这是BAD:如果我重命名一个属性(比方说,我要重新命名name
,以lastname
)我将手动更新我的所有代码.
我不希望这种依赖.
由于typescript接口没有JS实现,我不知道我怎么不能使用字符串.
我希望有类似的东西: methodX(IInterface.name.propertytoString(), objectX);
我是JS的新手,你看到另一种选择吗?
(可选)更多细节:为什么我需要将属性作为参数传递,为什么我不使用泛型方法?
我使用链接数据的方法:
linkData = <TA, TB>(
inputList: TA[],
inputId: string,
inputPlace: string,
outputList: TB[],
outputId: string ) => {
var mapDestinationItemId: any = {};
var i: number;
for ( i = 0; …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的角度滤波器.
此过滤器接受输入枚举的成员(此处称为XEnum)并返回表示枚举中成员的字符串:
module Filters {
"use strict";
export function XEnumToStringFilter() {
return ( input: XEnum ) => {
return XEnum[input];
}
}
}
[...]
module Model {
export enum XEnum{
Started = 0,
Stopped = 1
}
}
[...]
app.filter( "xEnumToStringFilter", [Filters.XEnumToStringFilter] );
Run Code Online (Sandbox Code Playgroud)
当我在视图中使用xEnumToStringFilter时,这非常有效:
{{0 | etatTransfertEnumToStringFilter}}
打印 Started
{{1 | etatTransfertEnumToStringFilter}}
打印 Stopped
但我想在我的服务中使用此过滤器:
app.service( "serviceUsingXEnum",
["xEnumToStringFilter",
Services.ServiceUsingXEnum] );
Run Code Online (Sandbox Code Playgroud)
但在我的服务构造函数中,我只得到一个奇怪的错误:
module Services {
"use strict";
export class ServiceUsingXEnum {
constructor(
private xEnumToStringFilter: Filters.XEnumToStringFilter // error here
) {
// …
Run Code Online (Sandbox Code Playgroud)