Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce RedisStateMachine bytecode size #1323

Closed
hellyguo opened this issue Jun 26, 2020 · 5 comments
Closed

Reduce RedisStateMachine bytecode size #1323

hellyguo opened this issue Jun 26, 2020 · 5 comments
Labels
type: feature A new feature
Milestone

Comments

@hellyguo
Copy link
Contributor

Describe the solution you'd like

the method, decode(), in RedisStateMachine is so big. When convert it to bytecode, the size is great than 325 bytes.

Describe alternatives you've considered

using enum with behavior + lambda, we can reduce the method's size.

Teachability, Documentation, Adoption, Migration Strategy

JitWatch

@hellyguo
Copy link
Contributor Author

before

➜  jitwatch-1.3.0 ./jarScan.sh --mode=maxMethodSize --limit=325 --packages=io.lettuce.core.protocol ~/code/github/lettuce-core/target/classes
"io.lettuce.core.protocol","RedisStateMachine","decode","io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",571

after

➜  jitwatch-1.3.0 ./jarScan.sh --mode=maxMethodSize --limit=5 --packages=io.lettuce.core.protocol ~/code/github/lettuce-core/target/classes|grep -F RedisStateMachine
"io.lettuce.core.protocol","RedisStateMachine","loopPeekStack","io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",127
"io.lettuce.core.protocol","RedisStateMachine","decode","io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",109
"io.lettuce.core.protocol","RedisStateMachine","funcMulti","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",100
"io.lettuce.core.protocol","RedisStateMachine","funcBulk","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",75
"io.lettuce.core.protocol","RedisStateMachine","funcInteger","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",42
"io.lettuce.core.protocol","RedisStateMachine","funcSingle","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",39
"io.lettuce.core.protocol","RedisStateMachine","funcBytes","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",32
"io.lettuce.core.protocol","RedisStateMachine","funcError","io.lettuce.core.protocol.RedisStateMachine,io.lettuce.core.protocol.RedisStateMachine$State,io.netty.buffer.ByteBuf,io.lettuce.core.protocol.RedisCommand<?, ?, ?>,io.lettuce.core.output.CommandOutput<?, ?, ?>",28

@mp911de
Copy link
Collaborator

mp911de commented Jun 26, 2020

Can you explain the motivation behind this change?

@hellyguo
Copy link
Contributor Author

I'm working on a business project now. In my project, I need a fast 3rd lib to access redis. I may use some asynchronous scenarios. What lettuce has is What I needed.

I compared jedis and lettuce. After a simple(may be wrong) test, I found lettuce is not the fast one in my test.

I captured the thread dump. Found RedisStateMachine. Then I read the code, found the method.

My motivation is let lettuce run faster. But just a tiny improve.

  • reduce the method(decode), more readable, less bytecode size
  • split in several methods, may some is tiny enough that can be inline
  • prefer to use enum-interface-lambda, not switch-case

like what netty did

@mp911de mp911de linked a pull request Jun 29, 2020 that will close this issue
4 tasks
@mp911de
Copy link
Collaborator

mp911de commented Jun 29, 2020

Thanks a lot. I'll have a look.

@mp911de mp911de added this to the 5.3.2 milestone Jul 1, 2020
@mp911de
Copy link
Collaborator

mp911de commented Jul 1, 2020

That's merged now.

@mp911de mp911de closed this as completed Jul 1, 2020
@mp911de mp911de changed the title reduce method(decode)'s bytecode size Reduce RedisStateMachine bytecode size Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants