Electron项目yarn安装依赖

yarn 淘宝镜像

1
2
3
4
yarn config set registry https://registry.npm.taobao.org

yarn config get registry
https://registry.npm.taobao.org

Electron 淘宝镜像

1
export ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"

官方文档传送门

技术版五彩斑斓的黑

最近好几个post都只留了标题,迟迟补不上内容,有点要断更的尴尬😓。偶然看到个视频,觉得挺好的,发上来也算是续上了。


请欣赏视频


观后感

协商之下没有什么需求是满足不了的,如果有就换个表述😂

要永远充满信心才是合格的专家


附上一个五彩斑斓的黑
五彩斑斓的黑

crunch纹理压缩库的使用

扩展cocos2dx版的fbx-conv

Netty的ByteBuf与Protostuff序列化实现零拷贝

Cache friendly code

什么是缓存友好代码?学院派的回答大概会涉及CPU多级缓存结构等原理性的内容,但也许只要理解“缓存是CPU里一块比内存小很多,但也很多的存储空间,访问内存时CPU会一段一段的把内存读取到缓存,如果后续操作的数据在缓存里就不会读内存,整体速度就了”,这样的基本概念其实就可以开始编写缓存友好的代码了。

多核多线程时还会有False Sharing等问题,可以入门后再逐步了解。

下面是一段演示代码。对一个二维数组的数据求和,区别只是按“行”访问还是按“列”访问(会影响cache是否命中),品出其中差别也就算入门了。

在数据集小到可以全部放在cache中的时候,是真的飞起了,当然现实中很少有这样理想的情况,缓存友好的核心也就是如何设计能高命中的数据结构和代码。

常见的做法会把对象属性以线性存储,并分独立函数更新。这里会有点和面向对象拧着的感觉,需要适应一下,对外接口OOP内部组织DOP。

Unity的DOTS中的ECS(Entity Component System )是不错的概念参考。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <chrono>
#include <string>
#include <vector>

using namespace std;

template <int M, int N>
int sumarrayrows(int a[M][N])
{
int sum = 0;
for (int i = 0; i != M; ++i)
for (int j = 0; j != N; ++j)
sum += a[i][j];
return sum;
}

template <int M, int N>
int sumarraycols(int a[M][N])
{
int sum = 0;
for (int j = 0; j != N; ++j)
for (int i = 0; i != M; ++i)
sum += a[i][j];
return sum;
}

template <int M, int N>
void testCase()
{
cout << "testCase: " << M << "," << N << endl;
int data[M][N] = {1};
{
auto start = chrono::steady_clock::now();
int sum = 0;
for (int loop = 0; loop < 10000; loop++)
{
sum += sumarrayrows<M, N>(data);
}
auto end = chrono::steady_clock::now();
cout << "\tsum: " << sum << " time: " << chrono::duration_cast<chrono::microseconds>(end - start).count() << endl;
}

{
auto start = chrono::steady_clock::now();
int sum = 0;
for (int loop = 0; loop < 10000; loop++)
{
sum += sumarraycols<M, N>(data);
}
auto end = chrono::steady_clock::now();
cout << "\tsum: " << sum << " time: " << chrono::duration_cast<chrono::microseconds>(end - start).count() << endl;
}
}

int main()
{
testCase<10, 10>();
testCase<100, 100>();
}
1
clang ./cacheTest.cpp --std=c++14 -lstdc++ -O2 -o test.out
1
2
3
4
5
6
testCase: 10,10
sum: 10000 time: 5
sum: 10000 time: 306
testCase: 100,100
sum: 10000 time: 15380
sum: 10000 time: 74331

记一次ReactNative优化

这是一个试水项目,是找的代码做二次开发,在中低端手机上运行,滑动列表有点卡。

代码到手后总体浏览了一下,基本没有什么复杂计算,应该是对象创建和布局绘制占大头。

具体找到对应界面的样式和组件代码后,确实代码为了布局容易,层次嵌套比较多,样式书写简单直接,可以透明的容器都填充了颜色,经过一番调整,主要修改样式,部分扁平化层级后,问题解决。

这里不打算写具体修改的内容,原生平台的开发手册里都会有layout,overdraw和gpu profile相关的内容,里面有写的很好的指引说明。

(这里还改了react-navigation-stack里的StackViewCard,因为当时的版本,它的背景设置不了透明,本想略去的,因为本质还是改样式,但毕竟动到了三方组件里面,还是补充说明一下)


优化并不都是高深复杂的事情,很多时候认真做好基础的事情就已经能满足大部分需求。

看起来外在表现一样,可能对应的内在在代码不一样,优化在于用心。


overdraw对比 gpu对比
修改前overdraw 修改后overdraw 修改前gpu 修改后gpu

通webview注入实现接管scatter签名请求

演示截图

node.js代码加密的一次尝试

曾经有个合作项目用node.js开发的,大BOSS想软件给到对方时能不能不提供源码。

想到V8是有code cache的,如果把源码转成code cache不就满足需求了

因为是针对用户部署,版本兼容的问题可以先忽略

查了下node.js文档还真有相关接口暴露,经过一下午的折腾,搞出一个小工具

产生和使用code cache的接口很简单,折腾在require拦截,外加踩了个lazy compile的坑

不废话了,直接上代码

代码仓库传送门

GitHub Actions 搞定Hexo自动部署

第一次尝试 GitHub Actions,很赞👍

  • 语法简单,上手容易,但又足够强大,感觉可以干任何事情
  • 复用性强,很容易通过use复用,市场里有很多常用action
  • 配额给的足够

官方文档传送门

[当前仓库部署用的workflow]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Deploy

on:
[push] # 触发事件

jobs:
build:
runs-on: ubuntu-latest # 运行环境为最新版 Ubuntu
name: A job to deploy blog.
steps:
- name: Checkout # 获取源码
uses: actions/checkout@v1 # 使用官方常用action
with: # 条件
submodules: true

- name: copyCfg # 更新配置
run: cp _config.theme.yml themes/icarus/_config.yml

# Caching dependencies to speed up workflows. (GitHub will remove any cache entries that have not been accessed in over 7 days.)
- name: Cache node modules
uses: actions/cache@v1
id: cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true' # 如果没有cache
run: npm install # 安装 node modules 相关依赖

# 发布
- name: Deploy
id: deploy
uses: sma11black/hexo-action@v1.0.0 # 使用 社区贡献的action
with:
deploy_key: ${{ secrets.DEPLOY_KEY }}
user_name: xuewuli
user_email: 26448247@qq.com