Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
baichangda committed Aug 2, 2024
1 parent 258ea6b commit 22e431d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion parser-base/src/main/java/cn/bcd/parser/base/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cn.bcd.parser.base.util.BitBuf_writer_log;
import cn.bcd.parser.base.util.LogUtil;
import cn.bcd.parser.base.util.ParseUtil;
import io.netty.buffer.AbstractByteBuf;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import javassist.*;
Expand Down Expand Up @@ -66,7 +67,6 @@
* {@link ParseUtil#needLog(BuilderContext)}
*/
public class Parser {

private final static Logger logger = LoggerFactory.getLogger(Parser.class);

public final static Map<Class<? extends Annotation>, FieldBuilder> anno_fieldBuilder;
Expand All @@ -93,6 +93,18 @@ public class Parser {
*/
private static boolean printBuildLog = false;

/**
* 禁用ByteBuf检查
* 这样做会使性能提高10%~20%
* 原因是在读取{@link ByteBuf}时候会进行如下两个检查
* {@link AbstractByteBuf#checkAccessible} 可访问检查
* {@link AbstractByteBuf#checkBounds} 边界检查
*/
public static void disableByteBufCheck() {
System.setProperty("io.netty.buffer.checkBounds", "false");
System.setProperty("io.netty.buffer.checkAccessible", "false");
}

public static void withDefaultLogCollector_parse() {
logCollector_parse = new LogCollector_parse() {
/**
Expand Down Expand Up @@ -180,6 +192,7 @@ public void collect_class(Class<?> clazz, int type, Object... args) {
}
}
}

@Override
public void collect_field(Class<?> clazz, String fieldName, int type, Object... args) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void test() {

@Test
public void test_performance() {
Parser.disableByteBufCheck();
Parser.enablePrintBuildLog();
Parser.enableGenerateClassFile();
String data = "232303FE4C534A41323430333048533139323936390101351403190F0507010203010000000469B00EE5271055020F1FFF000002010103424E1E4E2045FFFF2710050006BE437001CF306A060160FFFF0101FFFF0118FF01010E070000000000000000000801010EE527100060000160FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF09010100180EFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void test() {

@Test
public void test_performance() {
// Parser.enablePrintBuildLog();
Parser.disableByteBufCheck();
Parser.enablePrintBuildLog();
Parser.enableGenerateClassFile();
// Parser.withDefaultLogCollector_parse();
// Parser.withDefaultLogCollector_deParse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void test() {

@Test
public void test_performance() {
Parser.disableByteBufCheck();
Parser.enablePrintBuildLog();
Parser.enableGenerateClassFile();
String data = "7e0200407c0100000000017299841738ffff000004000000080006eeb6ad02633df701380003006320070719235901040000000b02020016030200210402002c051e3737370000000000000000000000000000000000000000000000000000001105420000004212064d0000004d4d1307000000580058582504000000632a02000a2b040000001430011e310128637e";
Expand Down

0 comments on commit 22e431d

Please sign in to comment.